1

I am looking for a pre-compiler to introduce a customized syntax into LaTeX.

Hope that an example will be worth a thousand words: I would like to compile this

\thm
The sum 
$ 1+2+3
is equal to
$$[six] 6. 
% this line will be skipped
\proof
$$ 1+2 &= 3
$$ 1+2+3 &= 6

to obtain this

\begin{theorem}
The sum
$ 1+2+3 $
is equal to
\begin{align}
\label{six}
6.
\end{align}
\end{theorem}
\begin{proof}
\begin{align*}
1+2 &= 3\\
1+2+3 &= 6
\end{align*}
\end{proof}

and then run the standard LaTeX compiler on the latter.

I was wondering if there is some fast/clever way to do this.

  • 1
    Whatever you end up with, please see http://tex.stackexchange.com/questions/503/why-is-preferable-to – Ethan Bolker Feb 13 '14 at 01:41
  • Why? I am not even using $$ ... $$ syntax in my compiler output. – Evariste Feb 13 '14 at 09:16
  • However I don't completely understand why this has been put on hold. Wouldn't a solution written in TeX be on-topic? Should I add this requirement to the question? – Evariste Feb 13 '14 at 09:36

1 Answers1

0

You could write a program in e.g. Perl to do such a translation. But it is probably nicer to just define your own commands to take some arguments and spit out what you want. Their use will turn out quite messy, unless you design them carefully.

Perhaps you can coax your editor to do (part of) the heavy lifting? Perhaps just spitting out a template to fill in (or grab it from a file) could help. I know for a fact that emacs can do much more than that, and AFAIU latest versions of vi(1) can be extended in usable languages (althought I remember a maze solver written in vi's original one-letter commands, so...).

vonbrand
  • 5,473