vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

asy-latex one line processing #436

Open mdoob opened 3 months ago

mdoob commented 3 months ago

The asy environment used for inline code within a LaTeX document is defined starting on line 244 here: https://github.com/vectorgraphics/asymptote/blob/master/doc/asy-latex.dtx). Lines are read in one at a time until one matches \end{asy}.

The code for doing this: \gdef\ProcessAsymptoteLine#1^^M{% \def\@tempa{#1}% {% \escapechar=-1\relax% \xdef\@tempb{\string\end\string{\CurrentAsymptote\string}}% }% \ifx\@tempa\@tempb% \edef\next{\endgroup\noexpand\end{\CurrentAsymptote}}% \else% \ThisAsymptote{#1}% \let\next\ProcessAsymptoteLine% \fi% \next% }

The lines in boldface test for the line match.

It appears (naively?) to be pretty easy to extend the definition of this macro to one that it terminates after exactly one line. Why might this be useful?

  1. It could be used within other macros since it does on depend on line breaks.
  2. It is unaffected by an unexpected reformatting.
  3. It would be convenient for small inserts.
  4. One line may have many semicolons :smile:.

Any thoughts?