Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.synctex.gz
/*.pdf
/*.tex
build/
6 changes: 3 additions & 3 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ docker build -t kokkos_cheat_sheet .

## Generate LaTeX files

Call the `convert.sh` script which pre-processes the input Markdown file and converts it to standalone LaTeX sources:
Call the `scripts/convert.sh` script which pre-processes the input Markdown file and converts it to standalone LaTeX sources:

```sh
./convert.sh <file.md>
./scripts/convert.sh <file.md>
# or
docker run --rm -v $PWD:/work docker_cheat_sheet ./convert.sh <file.md>
docker run --rm -v $PWD:/work docker_cheat_sheet ./scripts/convert.sh <file.md>
```

Note that an additional `--user $UID:$GID` can be required to produce a file with your ownership on some systems.
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ Namely, such changes include manual page breaks, abbreviations, etc.
Large modification, however, such as the removal of an entire section, are better handled by the pre-processor discussed above.

A patch is associated with a converted file in the form `name.ext.diff`, and is stored under `patches/<mode>/name.ext.diff` (with `<mode>` being `print` for print mode).
If a patch file exists with the same name, then the patch is automatically applied when calling `convert.sh`.
If a patch file exists with the same name, then the patch is automatically applied when calling `scripts/convert.sh`.

The creation of the patch uses the following workflow:

```sh
./generate_patch.sh <file.md> start
./scripts/generate_patch.sh <file.md> start
# edit <file.tex> and perform specific adjustments
./generate_patch.sh <file.md> end
./scripts/generate_patch.sh <file.md> end
```

Any consecutive call to `generate_patch.sh` will cumulate the modifications.
Any consecutive call to `scripts/generate_patch.sh` will cumulate the modifications.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 17 additions & 10 deletions convert.sh → scripts/convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ GPP_USERMODE_CHARACTER_UNSTACK=')'
GPP_USERMODE_NUMBER='#'
GPP_USERMODE_QUOTE=''

# Path of the script directory
# https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Path of the project directory
PROJECT_DIR=$(dirname "$SCRIPT_DIR")

convert () {
local input_file="$1"
local output_file="$2"
Expand All @@ -37,20 +44,20 @@ convert () {
"$input_file" \
| \
pandoc \
--defaults "configs/print.yaml" \
--include-in-header "styles/header/print.tex" \
--include-before-body "styles/before_body/print.tex" \
--include-after-body "styles/after_body/print.tex" \
--filter "filters/print.py" \
--output "$output_file"
--defaults "$PROJECT_DIR/configs/print.yaml" \
--include-in-header "$PROJECT_DIR/styles/header/print.tex" \
--include-before-body "$PROJECT_DIR/styles/before_body/print.tex" \
--include-after-body "$PROJECT_DIR/styles/after_body/print.tex" \
--filter "$PROJECT_DIR/filters/print.py" \
--output "$PWD/$output_file"

echo "Converted to $output_file"
}

patch_modifs () {
local output_file_diff="$1"

patchfile="patches/print/$output_file_diff"
patchfile="$PROJECT_DIR/patches/print/$output_file_diff"

if [[ ! -f "$patchfile" ]]
then
Expand All @@ -63,7 +70,7 @@ patch_modifs () {
# command returns non-0 and stores them in a specific reject file. First,
# the call is marked to never fail, and second, this reject file is
# discarded.
patch --quiet --forward --reject-file - <"$patchfile" || true
patch --quiet --forward --reject-file - --no-backup-if-mismatch <"$patchfile" || true

echo "Applied patch from $output_file_diff"
}
Expand All @@ -86,12 +93,12 @@ EOF

get_out_file () {
local input_file="$1"
echo "${input_file%.*}.tex"
echo "$(basename ${input_file%.*}.tex)"
}

get_out_file_diff () {
local output_file="$1"
echo "$output_file.diff"
echo "$(basename $output_file.diff)"
}

main () {
Expand Down
16 changes: 12 additions & 4 deletions generate_patch.sh → scripts/generate_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

set -eu

source convert.sh
# Path of the script directory
# https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Path of the project directory
PROJECT_DIR=$(dirname "$SCRIPT_DIR")

source "$SCRIPT_DIR/convert.sh"

get_out_file_ref () {
local output_file="$1"
Expand Down Expand Up @@ -30,16 +37,17 @@ end_patch () {

if [[ ! -f "$output_file_ref" ]]
then
echo "Please call \"generate_patch.sh $input_file start\" first!"
relative_path=$(realpath --relative-to "$PWD" "$SCRIPT_DIR")
echo "Please call \"$relative_path/generate_patch.sh $input_file start\" first!"
return 1
fi

mkdir -p "patches/print"
mkdir -p "$PROJECT_DIR/patches/print"

# generate diff
# Note: If there is an actual difference between the two files, the diff
# command returns non-0. Consequently, the call is marked to never fail.
diff -au "$output_file_ref" "$output_file" >"patches/print/$output_file_diff" || true
diff -au "$output_file_ref" "$output_file" >"$PROJECT_DIR/patches/print/$output_file_diff" || true

# remove reference file
rm --force "$output_file_ref"
Expand Down