about summary refs log tree commit diff stats
path: root/build/latex/presentation/scripts/fix_notes.sh
blob: c5caf5bf4af935a6231c93ebe12b436bf84cd830 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env sh

# Compiling this document with pdflatex, will leave all utf8 chars in the `\note`s
# mangled. But, `pdfpc` interprets them as markdown, thus replacing all of them with their
# respective html entities results in them looking correct in during the presentation.
#
# This script automatically replaces them in the source files.
#
# # Known Bugs
# It does not account for `\note`s spanning multiple lines. So, for example, this would not
# be fixed:
# ```latex
# \note {
#   Ästhetik ist hierbei nicht mit den Wundern der Kunst zu verwechseln.
# }
# ```

rg '\\note' --files-with-matches | while IFS= read -r file; do
    [ "$(basename "$file")" = "$(basename "$0")" ] && continue

    echo "Fixing: '$file'"
    sed --in-place 's/^\(.*\)\\note\(.*\){\(.*\)}/printf "%s\\\\\\note%s{%s}" "\1" "\2" "$( echo "\3" | sed "s@ä@\\\&auml\;@g" | sed "s@ö@\\\&ouml\;@g" | sed "s@ü@\\\&uuml\;@g" | sed "s@Ä@\\\&Auml\;@g" | sed "s@Ö@\\\&Ouml\;@g" | sed "s@Ü@\\\&Uuml\;@g" | sed "s@ß@\\\&szlig\;@g" | sed "s@→@\\\&rarr\;@g" )"/eg' "$file"
done