Shake your LaTeX syntax tree!
$ echo '\\newif\\ifah\\ahtrue\\ifah Shake it! :) \\else Do not shake it... :( \\fi' | texshake
Shake it! :)$ npm i -g texshake$ texshake < 'my-awesome-latex-file-before.tex' > 'my-awesome-latex-file-after.tex'Prunes dead branches for \iftrue's, \iffalse's, and user-defined \if... variables.
\abctrue\ifabc ah\else oh\fi~ah
Only keeps the first % character of each comment.
hello, world % Lorem ipsum dolor sit amet~hello, world %
Expands each user-defined macro and removes their definition.
\newcommand\swap[2]{#2#1}\swap{a}{b}~ba
\newenvironment{items}{\begin{itemize}}{\end{itemize}}\begin{items}\end{items}~\begin{itemize}\end{itemize}
\myfalse\ifmy\def\xyz{A cat.}\else\def\xyz{A dog.}\fi\xyz% $#@!~A dog.%
I use it for scientific publications. I often need different versions of
the same paper for different occasions: conference proceedings, journal
version, arXiv preprint. I just write the content once, with the right
conditionals, macro definitions and \input calls. I flatten everything using
flatex,
shake the document with texshake, and finally get rid of all extraneous
blanks with
textrim.
It uses @aureooms/js-tape and @aureooms/js-grammar under the hood.
The tokens are produced according to this file and the shaking logic lies in this file.