-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmd2tex
executable file
·46 lines (38 loc) · 1 KB
/
md2tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env sh
# vim: ft=sh ts=4 sw=4 sts=4 et :
# Get absolute path without using realpath/readlink
abs_path() {
case "$1" in
/*) printf '%s\n' "$1" ;;
*) printf '%s/%s\n' "$PWD" "$1" ;;
esac
}
md2tex() {
pandoc \
--standalone \
-f markdown-implicit_figures \
-t latex \
"$1" \
-o "${1%.md}.tex"
}
main() {
if [ $# -eq 0 ]; then
echo "Error: no input files" >&2
printf "Usage: %s files...\n" "$(basename "$0")" >&2
exit 1
fi
for file in "$@"; do
oldpwd=$PWD
# Pictures in markdown cannot be fetched if we are not in the same
# directory
cd "$(dirname "$(realpath "$file")")" >/dev/null 2>&1 || exit 1
if ! md2tex "$(basename "$file")"; then
rc=$?
echo "md2tex: error: pandoc failed to convert '$file' with exit code $rc" >&2
cd "$oldpwd" >/dev/null 2>&1
exit $rc
fi
cd "$oldpwd" >/dev/null 2>&1
done
}
main "$@"