2021-11-09 06:46:22 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2021-11-14 13:42:06 +03:00
|
|
|
# Generate docs from latex package/class...
|
|
|
|
|
#
|
|
|
|
|
# Usage: cls2tex.sh INPUT OUTPUT [PREFIX]
|
|
|
|
|
#
|
|
|
|
|
# - keep lines starting with \def\<module-name>@[A-Z]\+
|
|
|
|
|
# - keep lines starting with '%%'
|
|
|
|
|
# - %%%%% Text -> \subsection(Text)
|
|
|
|
|
# - %%%% Text -> \section(Text)
|
|
|
|
|
# - %% >> code -> \begin{verbatim}code\end{verbatim}
|
|
|
|
|
#
|
|
|
|
|
# NOTE: the idea of keeping latex docs in a latex file is far similar
|
|
|
|
|
# than all the stuff crammed into .dtx, at least for my needs:
|
|
|
|
|
# - keep the code readable
|
|
|
|
|
# - keep the docs readable
|
|
|
|
|
# in both the repo and in installed form.
|
|
|
|
|
# NOTE: this is evolving as need arises, when this gets too complicated
|
|
|
|
|
# we'll split it out into it's own script.
|
2021-11-09 06:46:22 +03:00
|
|
|
|
2021-11-14 13:42:06 +03:00
|
|
|
INPUT=$1
|
2021-11-09 06:46:22 +03:00
|
|
|
|
2021-11-14 13:42:06 +03:00
|
|
|
OUTPUT=$2
|
|
|
|
|
|
|
|
|
|
PREFIX=$3
|
|
|
|
|
if [ -z $PREFIX ] ; then
|
|
|
|
|
PREFIX=%
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cat "$INPUT" \
|
|
|
|
|
| egrep '(^%'$PREFIX'|^\\edef\\.*@[A-Z][A-Z]+)' \
|
|
|
|
|
| sed 's/^\(\\edef\\\).*@/%'$PREFIX'\1/' \
|
|
|
|
|
| sed 's/%'$PREFIX'%%%% \(.*\)/%'$PREFIX'\\subsubsection{\1}\\label{subsubsec:\1}/' \
|
|
|
|
|
| sed 's/%'$PREFIX'%%% \(.*\)/%'$PREFIX'\\subsection{\1}\\label{subsec:\1}/' \
|
|
|
|
|
| sed 's/%'$PREFIX'%% \(.*\)/%'$PREFIX'\\section{\1}\\label{sec:\1}/' \
|
|
|
|
|
| sed 's/%'$PREFIX'\s\+>>\s\+\(.*\)/%'$PREFIX'\\begin{verbatim} \1 \\end{verbatim}/' \
|
|
|
|
|
| cut -c 3- - > "$OUTPUT"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# vim:set ts=4 sw=4 nowrap :
|