Gmp 包中的 vardef 后缀宏有错误吗?

Gmp 包中的 vardef 后缀宏有错误吗?

我认为我遇到了一个 gmp 错误,其中 vardef 宏名称“mymacro@#”在生成的 metapost 文件中被写为“mymacro@##”。这是我第一次使用 gmp 包,我可能遗漏了一些东西。有人能确认这是一个错误吗?如果它确实是一个错误,是否有一些解决方法或可能的修复方法?

短暂性失眠!

TeX 输入:

\documentclass{article}
\usepackage[shellescape]{gmp}
\begin{document}
\begin{mpost}
u=2cm;

vardef mymacro@#=
  pair @#.mid;
  @# := (0u, 0u) -- (50u, 75u);
  @#.mid := 0.5[(0u, 0u), (50u, 75u)];
enddef;

path a;

mymacro.a;
draw a;
\end{mpost}
\end{document}

日志档案:

This is MetaPost, version 2.00 (TeX Live 2019) (kpathsea version 6.3.1)  29 NOV 2019 13:41
**foo+mp0001
(/usr/local/texlive/2019/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2019/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./foo+mp0001.mp
>> mymacro.a
! Isolated expression.
<to be read again> 
                   ;
l.14  mymacro.a;

I couldn't find an `=' or `:=' after the
expression that is shown above this error message,
so I guess I'll just ignore it and carry on.

>> unknown path a
! Improper `addto'.
<to be read again> 
                   withpen
draw->...:also(EXPR0)else:doublepath(EXPR0)withpen
                                                  .currentpen.fi._op_
<to be read again> 
                   ;
l.15  draw a;

This expression should have specified a known path.
So I'll not change anything just now.

[1] )
1 output file written: foo+mp0001.mps

metapost 文件:

%% Do not edit, this file has been generated
%% automatically by foo.tex via gmp.sty

outputtemplate:= "%j.mps";
beginfig(1);
u=2cm;

vardef mymacro@##= pair @##.mid;
 @## := (0u, 0u) -- (50u, 75u);
 @##.mid := 0.5[(0u, 0u), (50u, 75u)];
 enddef;

path a;
 mymacro.a;
 draw a;

endfig;
end.

答案1

是的,这看起来像是一个错误。扫描环境时mpost,包不会将 catcode 设置为#12因此 TeX 会将其加倍,就像往常一样。您需要添加\do\#\gmp@otherchars

\makeatletter %                                       added vvvvv
\def\gmp@otherchars{\do\!\do\=\do\:\do\"\do\?\do\'\do\`\do\|\do\#}
\makeatother

添加该代码(并稍微减少行的长度以适合页面),代码就可以正常工作:

\documentclass{article}
\usepackage[shellescape]{gmp}
\makeatletter
\def\gmp@otherchars{\do\!\do\=\do\:\do\"\do\?\do\'\do\`\do\|\do\#}
\makeatother
\begin{document}
\begin{mpost}
u=2cm;

vardef mymacro@#=
  pair @#.mid;
  @# := (0u, 0u) -- (5u, 7u);
  @#.mid := 0.5[(0u, 0u), (5u, 7u)];
enddef;

path a;

mymacro.a;
draw a;
\end{mpost}
\end{document}

在此处输入图片描述

相关内容