lualatex / luamplib

generic TeX package - including MetaPost code in LuaTeX documents
http://ctan.org/pkg/luamplib
16 stars 11 forks source link

Labels and LaTeX macros don't go well together #39

Closed franckpastor closed 10 years ago

franckpastor commented 10 years ago

Hello,

I've just tried to typeset multiline labels inside a mplibcode environment, and I've noticed unexpected behaviors. The following program tries to sum up all the experiments I've made on this subject.

\documentclass{article}
\usepackage{luamplib}
\newcommand{\try}[2]{\begin{tabular}{cc} #1\\ #2 \end{tabular}}
\newcommand{\secondtry}[2]{\tabular{cc} #1 \\ #2 \endtabular}
\begin{document}
\begin{mplibcode}
beginfig(1);
label(btex \try ! ? etex, origin); % works
%label(btex \try{!}{?} etex, origin); % don't work! "Missing number, treated as zero.<to be read again> \crcr
%label(btex \begin{tabular}{cc} ! \\ ? \end{tabular} etex, (1cm, 0)); % don't work! "Missing \encsname inserted" <to be read again>\protect
label(btex \tabular{cc} ! \\ ? \endtabular etex, (1cm, 0)); % works…
%label(btex \secondtry{!}{?} etex, (2cm, 0)); %don't work! "Missing number, treated as zero" <to be read again> \crcr
endfig;
\end{mplibcode}

\end{document}

First, I tried to define a LaTeX command \try typesetting two lines of text, via a tabular environment. As shown in the comments of the program, this macro works when inserted as \try ! ?inside a label instruction, between the btex and etex flags. But inserted as \try{!}{?}, it doesn't work.

It doesn't work either if I try to insert the tabular environment directly in the label, in this form btex \begin{tabular}{cc} ! \\ ? \end{tabular} etex. But it does work with the syntax btex \tabular{cc} ! \\ ? \endtabular etex. Inspired by this, I tried to define another macro, the \secondtry of my example, using this syntax, but it won't work either.

All these examples work fine with standalone MetaPost.

I hope I've not been too confusing, but in fact I'm a bit confused by all this. It reminds me the kind of problems you may encounter when using the gmp package (it's this package's documentation which gave me the \tabular … \endtabular trick, by the way), but it seems more complex than this. What could be the explanation?

franckpastor commented 10 years ago

Edit: I've forgotten the last line of my program, \end{document} (as I already said, I can't edit my posts since my browser is not supported by GitHub anymore).

franckpastor commented 10 years ago

Another typo: it must be read \begin{tabular}{c} and not \begin{tabular}{cc} in the examples. It doesn't change anything about the error messages, though.

franckpastor commented 10 years ago

UPDATE: Inserting a space between \begin{tabular} and {c} inside the btex and etex flags, and between the two arguments of the \try macro, make the problematic examples suddenly work. So the following program runs fine:

\documentclass{article}
\usepackage{luamplib}
\newcommand{\try}[2]{\begin{tabular}{c} #1 \\ #2 \end{tabular}}
\begin{document}
\begin{mplibcode}
beginfig(1);
label(btex \try{!} {?} etex, origin);
label(btex \begin{tabular} {c} ! \\ ? \end{tabular} etex, (1cm, 0));
endfig;
\end{mplibcode}
\end{document}

Still, I'm more baffled than ever when it comes to explain this…

dohyunkim commented 10 years ago

There's a bug in parsing routine. I have an idea how to patch, but today I'm so busy. Will be back tommorrow.

dohyunkim commented 10 years ago

It turned out that there was a silly bug in the parsing code. Very shameful to me. Asterisk (*) is a special character in the lua string manipulation. However I overlooked it carelessly. Pushed a patch a moment ago. @franckpastor Thank you very much for testing and finding this bug.

franckpastor commented 10 years ago

The patched version has removed the problem. Cheers again!

In my country it is said that the only device without defect is the one that has not yet been build. So there's nothing to be ashamed of! ;-)