Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vardef macros with suffix do not work as usual with luamplib #55

Closed
franckpastor opened this issue Mar 25, 2015 · 3 comments
Closed

vardef macros with suffix do not work as usual with luamplib #55

franckpastor opened this issue Mar 25, 2015 · 3 comments

Comments

@franckpastor
Copy link

Hello,

I was surprised today to notice that the following program did not work:

\documentclass{article}
\usepackage{luamplib}
\begin{document}
  \begin{mplibcode}

    vardef rotatedlabel@#(expr str, loc, angl) =
      draw thelabel@#(str, loc) rotatedaround(loc, angl)
    enddef;

    beginfig(1);
      rotatedlabel.top(textext("Rotated!"), origin, 45);
    endfig; 
  \end{mplibcode}
\end{document}

While I expected the same result as with standalone MetaPost, i.e. a rotated label:

capture d ecran 2015-03-25 a 22 03 11

I got this error message instead:

Illegal parameter number in definition of \mplibtemp.
<to be read again> 
(
l.15   \end{mplibcode}

If I ask more precisions by entering h in the console, I read:

You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I''m going to assume that you meant ##.

And indeed, if I replace # by ## in the vardef definition, i.e. like that,

vardef rotatedlabel@##(expr str, loc, angl) =
  draw thelabel@##(str, loc) rotatedaround(loc, angl)
enddef;

it suddenly works like a charm. OK, problem solved it seems, but I would like to understand the reasons of this peculiar behavior. Why must we enter ## instead of # with luamplib, whereas only one # is enough with standalone MetaPost? Any idea?

Thanks in advance,

Franck Pastor

@franckpastor franckpastor changed the title vardef macros with suffix do not work as usual with luamplib vardef macros with suffix do not work as usual with luamplib Mar 25, 2015
dohyunkim added a commit to dohyunkim/luamplib that referenced this issue Mar 26, 2015
dohyunkim added a commit that referenced this issue Mar 26, 2015
fix bug #55 regarding hash token
@dohyunkim
Copy link
Contributor

Thanks a lot.
Fixed in v2.10.1

dohyunkim added a commit to dohyunkim/luamplib that referenced this issue Mar 26, 2015
dohyunkim added a commit that referenced this issue Mar 26, 2015
@franckpastor
Copy link
Author

You are welcome! May I ask you what was the cause of this bug?

@dohyunkim
Copy link
Contributor

There was no problem before the introduction of \mpdim and allowing other TeX macros. But now as TeX macros (not all but only simple macros) are allowed in mplib code, we should take care macro expansion by TeX, which complains about single hash tokens (#). Latest patch simply doubles hash tokens before the TeX's macro expansion stage, and restores them to sinlge hash tokens after that process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants