diff --git a/Makefile b/Makefile index 2a10d26..e224c6f 100644 --- a/Makefile +++ b/Makefile @@ -226,6 +226,7 @@ LN := cp -l # strip docs out... # # XXX can we unify these??? +# ....not sure how... %-stripped.tex: %.tex $(DOC) --strip $< \ $(DOC) --prefix M --strip \ diff --git a/scripts/cls2tex.sh b/scripts/cls2tex.sh index 9119cd6..c0db7c8 100755 --- a/scripts/cls2tex.sh +++ b/scripts/cls2tex.sh @@ -1,157 +1,1588 @@ -#!/usr/bin/env bash -#---------------------------------------------------------------------- - -CMD="$0 $@" - -SCRIPT_NAME=$(basename $0) - -printusage(){ - echo "Usage:" - echo " $SCRIPT_NAME [OPTIONS] [[INPUT] OUTPUT]" -} - -printhelp(){ - echo "Generate docs from latex package/class" - echo - printusage - echo - echo "Options:" - echo " -h | --help Show this message and exit" - echo " -p | --prefix PREFIX" - echo " Set the doc comment PREFIX (default: \"%\")" - echo " -s | --strip Strip docs out" - echo " -n | --no-msg Don't add the \"generated with\" message to output" - echo - echo "This will:" - echo " - read the INPUT" - echo " - keep lines starting with \\def\\@[A-Z]\\+" - echo " - keep lines starting with '%%'" - echo " - %%%%% Text -> \\subsection{Text}" - echo " - %%%% Text -> \\section{Text}" - echo " - %% >> code -> \\begin{verbatim}code\\end{verbatim}" - echo " - write the result to OUTPUT" - echo - echo "If no OUTPUT is given $SCRIPT_NAME will write to stdout. If no INPUT" - echo "is given $SCRIPT_NAME will read stdin." - echo - 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 - echo "Strip mode is the reverse of of the default, it will strip out docs" - echo "and empty lines, keeping only the actual code and code comments." - echo - echo "NOTE: stripping will not remove non-doc comments." - 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." -} - -# Usage: printerror MESSAGE... -printerror(){ - echo Error: $@ - echo - printusage -} - -# Usage: printmsg TEXT -printmsg(){ - # print message... - if [ -z $NO_MSG ] ; then - echo "%----------------------------------------------------------------------" - echo "% $1 file generated by:" - echo "% $CMD" - echo "% NOTE: multiple messages indicate multiple runs." - echo "%----------------------------------------------------------------------" - fi -} - - - -#---------------------------------------------------------------------- -# Args and defaults... - -PREFIX=% - -while true ; do - case $1 in - -h|--help) - printhelp - exit - ;; - -p|--prefix) - PREFIX=$2 - shift - shift - ;; - -s|--strip) - STRIP_DOC=1 - shift - ;; - -n|--no-msg) - NO_MSG=1 - shift - ;; - - # handle unknown options... - -*|--*) - printerror "unknown option \"$1\"" - exit - ;; - - # non-flag, option parsing done... - *) - break - ;; - esac -done - -INPUT=${1:-/dev/stdin} - -OUTPUT=${2:-/dev/stdout} - - -# generate the module name... -MODULE=$(basename "$INPUT") -MODULE=${MODULE/.*/} - - -#---------------------------------------------------------------------- -# do the work... - -# make docs... -if [ -z $STRIP_DOC ] ; then - printmsg "Documentation" \ - > "$OUTPUT" - cat "$INPUT" \ - | grep -E '(^%'$PREFIX'|^\\edef\\'$MODULE'@[A-Z][A-Z]+)' \ - | sed \ - -e 's/^\(\\edef\\\)'$MODULE'@/%'$PREFIX'\1/' \ - -e 's/%'$PREFIX'%%%% \(.*\)/%'$PREFIX'\\subsubsection{\1}\\label{subsubsec:\1}/' \ - -e 's/%'$PREFIX'%%% \(.*\)/%'$PREFIX'\\subsection{\1}\\label{subsec:\1}/' \ - -e 's/%'$PREFIX'%% \(.*\)/%'$PREFIX'\\section{\1}\\label{sec:\1}/' \ - -e 's/%'$PREFIX'\s\+>>\s\+\(.*\)/%'$PREFIX'\\begin{verbatim} \1 \\end{verbatim}/' \ - | cut -c 3- - \ - >> "$OUTPUT" - -# make stripped code... -else - printmsg "Stripped code" \ - > "$OUTPUT" - cat "$INPUT" \ - | grep -Ev '%'$PREFIX'' \ - | grep -Ev '^(\s*%)?\s*$' \ - >> "$OUTPUT" -fi - - - -#---------------------------------------------------------------------- -# vim:set ts=4 sw=4 nowrap : +%---------------------------------------------------------------------- +% Stripped code file generated by: +% ./scripts/cls2tex.sh --strip photobook.tex ./scripts/cls2tex.sh --prefix M --strip +% NOTE: multiple messages indicate multiple runs. +%---------------------------------------------------------------------- +%---------------------------------------------------------------------- +% Documentation file generated by: +% ./scripts/cls2tex.sh photobook.cls +% NOTE: multiple messages indicate multiple runs. +%---------------------------------------------------------------------- +% NOTE: \def\@[A-Z]+ macros will be visible to both the +% code and the generated docs... +\edef\FILEVERSION{v0.1.15} +\edef\FILEDATE{2023-03-18} + \documentclass{ltxdoc} +% \usepackage{iftex} +% \ifluatex +% \edef\pdfcompresslevel{\pdfvariable compresslevel} +% \edef\pdfobjcompresslevel{\pdfvariable objcompresslevel} +% \fi +% \pdfcompresslevel 0 +% \pdfobjcompresslevel 0 + \usepackage[a4paper,margin=25mm,left=55mm,nohead]{geometry} + % NOTE: this needs to load before hyperref or bookmarks will break... + % NOTE: loading hyperref here will break it loading later in one of + % the packages... + \usepackage{titlesec} + \usepackage[numbered]{hypdoc} + \usepackage{doctools} + \usepackage{needspace} + \usepackage[toc]{multitoc} + \renewcommand*{\multicolumntoc}{2} + \setlength{\columnseprule}{0.5pt} + \usepackage{imakeidx} + \makeindex[ + columns=1, + title=Alphabetical Index, + intoc, + options= -s photobook.ist ] +% \newcommand\DescribeGlobal[1]{% +% \DescribeMacro{#1}} + \newcommand\LEGACY[1][]{\fbox{LEGACY #1}} + \newcommand\EXPERIMENTAL[1][]{\fbox{EXPERIMENTAL #1}} +% sections to new pages... + \newcommand\sectionbreak{\Needspace{5\baselineskip}} + % remove section numbering... + \setcounter{secnumdepth}{0} + % paragraph configuration... + \setlength\parindent{0pt} + \setlength\parskip{0.5em} + \newcommand\blankfootnote[1]{% + \begingroup + \renewcommand\thefootnote{}% + \footnote{#1}% + \addtocounter{footnote}{-1}% + \endgroup} + \begin{document} + \title{\textsf{photobook} --- Document class for building photo-books + \thanks{This file describes version \FILEVERSION, + last revised \FILEDATE.}} + \author{Alex A. Naanou\thanks{E-mail: alex.nanou@gmail.com}} + \date{Released \FILEDATE} + \maketitle + \begin{abstract} + The |photobook| \LaTeX\space document class extends the |book| class + defining a set of parameters, meta-macros, macros and environments + with reasonable defaults to help typeset, build and print books mainly + based on visual/image content. + \end{abstract} + \tableofcontents +\section{Introduction}\label{sec:Introduction} + \LaTeX\ is great with textual and text-primary content with figures + peppered in, as long as pictures/figures flow within, with or as part + of text, vanilla \LaTeX\ is fantastic. + One can relatively easily stretch the flow concept to more complex + layouts introducing {\it even} and {\it odd} pages (the |book| class is + one example) and flow rules based on them, but the next step, {\it bleeds}, + combining page pairs into {\it spreads} as is often needed when designing + image-oriented books is lacking. Full-bleed images/pages can be implemented + manually, some more effort is needed to split something horizontally + into a page spread, but doing so for whole book's worth of content is + not practical -- automating and experimenting with this process is + how |photobook| began. + |photobook| extends the |book| class adding page layout types, bleeds + and other global geometry configuration, introduces the {\it page} and + {\it spread} as first-class elements into the document flow. These concepts + are generalized as |cell|s. A |cell| is similar to a figure, it can + be placed within the document flow, but unlike a figure a |cell| can + be aligned relative to a page, it can fill a page, a cell can even be + horizontally split to fill several pages (how spreads are implemented). + On top of the |cell|, {\it page}, and {\it spread} concepts, |photobook| + also builds a set of configurable high level macros and templates for + common use cases like full bleed image spreads, foldouts, ... etc. +\section{Usage}\label{sec:Usage} +\begin{verbatim} \documentclass[]{photobook} \end{verbatim} +\section{Options}\label{sec:Options} +\subsection{Page geometry}\label{subsec:Page geometry} + \DescribeMacro{blockwidth=} + \DescribeMacro{blockheight=} + \DescribeMacro{bindingoffset=} + \DescribeMacro{bleed=} + This is similar to what |geometry| does, but adds bleed support. + \begin{minipage}{\textwidth} + \begin{verbatim} + <---> bleed <---> bleed + + - - - - - - - - - - - - - - - - - - - - - + - + ^ + . . . | bleed + . +---------------------------------------+----- v . . --- + . | ^ . = . + . | . . . . . . | . . = . ^ + . |<-- blockwidth ----------------------->= . | + . | . | . . = . | + . | | . = . textheight + . | . Page | . . = . | + . | blockheight . = . | + . | . | . . = . | + . | | <---> bindingoffset | + . | . . . . . . | . . = . v + . | v . = . + . +---------------------------------------+----- ^ . . --- + . . . . | bleed + + - - - - - - - - - - - - - - - - - - - - - + - + v + . . + | <-- textwidth --------------> . | + ^ gutter + \end{verbatim} + \end{minipage} + \DescribeMacro{flatfold=} + Sets the clearance set aside for a flat fold, used for foldouts + (see: \nameref{subsec:Foldout page cells} section). + \DescribeMacro{pagefold=} + Sets the default fold type. + Can be |in| or |out|. + \DescribeMacro{foldout=} + Sets the default fold specification (i.e. sets |\defaultfoldout|). + For more information see: \nameref{subsec:Foldout page cells} section. +\subsection{layout}\label{subsec:layout} + \DescribeMacro{layoutmode=} + \DescribeMacro{block} + \DescribeMacro{endpaper} + \DescribeMacro{cover} + \DescribeMacro{jacket} + Sat page layout mode. +\begin{verbatim} layoutmode=