2021-11-09 06:46:22 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2021-11-16 00:58:45 +03:00
|
|
|
printhelp(){
|
|
|
|
|
echo "Generate docs from latex package/class"
|
|
|
|
|
echo
|
2021-11-17 19:51:48 +03:00
|
|
|
echo "Usage: $(basename $0) [-h|--help] INPUT OUTPUT [PREFIX]"
|
2021-11-16 00:58:45 +03:00
|
|
|
echo
|
|
|
|
|
echo "This will:"
|
|
|
|
|
echo " - keep lines starting with \\def\\<module-name>@[A-Z]\\+"
|
|
|
|
|
echo " - keep lines starting with '%%'"
|
|
|
|
|
echo " - %%%%% Text -> \\subsection(Text)"
|
|
|
|
|
echo " - %%%% Text -> \\section(Text)"
|
|
|
|
|
echo " - %% >> code -> \\begin{verbatim}code\\end{verbatim}"
|
|
|
|
|
echo
|
2021-11-18 16:49:24 +03:00
|
|
|
echo "PREFIX can replace the second \"%\" in the above patterns to make it"
|
|
|
|
|
echo "possible to integrate multiple layers of documentation in one file"
|
|
|
|
|
echo "and to integrate them in various ways, for example, in the photobook"
|
|
|
|
|
echo "document class documentation \"M\" prefix is used to indicate"
|
|
|
|
|
echo "meta-command docs, this enables us to document them in the relevant"
|
|
|
|
|
echo "location (i.e. at the implementation) in source but move the docs to"
|
|
|
|
|
echo "a unified location in docs, effectively decoupling the source and doc"
|
|
|
|
|
echo "structure when needed."
|
|
|
|
|
echo
|
2021-11-16 00:58:45 +03:00
|
|
|
echo "NOTE: the idea of keeping latex docs in a latex file is far simpler"
|
|
|
|
|
echo " than all the stuff crammed into .dtx, at least for my needs:"
|
|
|
|
|
echo " - keep the code readable"
|
|
|
|
|
echo " - keep the docs readable"
|
|
|
|
|
echo " in both the repo and in installed form, so .dtx is not used."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# args/defaults...
|
|
|
|
|
while true ; do
|
|
|
|
|
case $1 in
|
|
|
|
|
-h|--help)
|
|
|
|
|
printhelp
|
|
|
|
|
exit
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
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
|
|
|
|
|
|
2021-11-18 16:49:24 +03:00
|
|
|
# generate the module name...
|
|
|
|
|
MODULE=$(basename "$INPUT")
|
|
|
|
|
MODULE=${MODULE/.*/}
|
2021-11-14 13:42:06 +03:00
|
|
|
|
2021-11-16 00:58:45 +03:00
|
|
|
# do the work...
|
2021-11-14 13:42:06 +03:00
|
|
|
cat "$INPUT" \
|
2021-11-18 16:49:24 +03:00
|
|
|
| egrep '(^%'$PREFIX'|^\\edef\\'$MODULE'@[A-Z][A-Z]+)' \
|
|
|
|
|
| sed 's/^\(\\edef\\\)'$MODULE'@/%'$PREFIX'\1/' \
|
2021-11-14 13:42:06 +03:00
|
|
|
| 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}/' \
|
2021-11-16 00:58:45 +03:00
|
|
|
| cut -c 3- - \
|
|
|
|
|
> "$OUTPUT"
|
2021-11-14 13:42:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# vim:set ts=4 sw=4 nowrap :
|