在 LuaLaTeX 中使用 Spy 时出现缺失数字错误

在 LuaLaTeX 中使用 Spy 时出现缺失数字错误

我有一张涉及透镜和光束的图表,pst-optexp为了方便和准确,我使用包制作了这张图表。所以我不得不使用 LuaLaTeX 进行编译。但是我想使用spy库来tikz放大图表的某些部分。问题是,每当我使用该\spy命令时,我都会收到以下错误:

! Missing number, treated as zero.
<to be read again> 
{
l.25    \end{tikzpicture}

代码如下:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{spy}
\usepackage{pst-optexp}
\newsavebox\Lens

\begin{document}
    \savebox\Lens={
    \begin{pspicture}
        \pnodes(0,0){A}(3,0){B}
        \pnodes(6.5,0){E}(0.5,0){F}
        \lens[n=1.5,lensheight=2.54,lenswidth=0.9,lensradiusleft=2.264,lensradiusright=0](A)(B){}
        \drawbeam[linecolor=black,beamangle=0,beampos=0,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=blue,beamangle=0,beampos=0.75,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=purple,beamangle=0,beampos=1,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=green,beamangle=0,beampos=-0.75,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=yellow,beamangle=0,beampos=-1,linewidth=0.6\pslinewidth](F){1}(E)
        \psline(6.5,-0.25)(6.5,0.25)
    \end{pspicture}
    }
    \begin{tikzpicture}[spy using outlines={circle,black,magnification=4,size=2cm}]
    \node at (0,0){\usebox\Lens};
%%  \spy on (1,0) in node at (3,-2); <-- Issue with this line
    \end{tikzpicture}

\end{document}

输出为

没有 spy 命令的输出

我想要的输出应该是这样的: 在此处输入图片描述

我不知道spyPSTricks 中是否有类似的情况。这种错误可能是什么原因造成的?

答案1

该示例可以简化为

\documentclass{article}
\makeatletter
  %     pgf/tex/generic/pgf/systemlayer/pgfsys.code.tex
  \directlua{
  local lft = lua.get_functions_table()
  lft[\string#lft+1] = function()
      local lhs = token.scan_string()
      local rhs = token.scan_string()
      if lhs < rhs then
          tex.sprint(-2, "-1")
      elseif lhs == rhs then
          tex.sprint(-2, "0")
      else
          tex.sprint(-2, "1")
      end
  end
  token.set_lua("pgfsys@strcmp", \string#lft, "global")
  }


\typeout{^^J!!!!1: \meaning\pgfsys@strcmp^^J\pgfsys@strcmp{aa}{bb}}

%\directlua{require'luapstricks'}%
\directlua{
local func = luatexbase.new_luafunction'luaPST'
token.set_lua('luaPST', func, 'protected')
lua.get_functions_table()[func] = function()
 local x = token.scan_string()
end
}

\typeout{^^J!!!!2:  \meaning\pgfsys@strcmp^^J\pgfsys@strcmp{aa}{bb}}


\begin{document}

\end{document}

两个!!!测试都应为 -1,但事实aa并非如此,bb但第二个测试返回{bb}最终导致标题中的错误。

在两种情况下的实际定义\pgfsys@strcmp是相同的(luacall #25),这意味着某处声明的 tex 函数的 lua 表被搞乱了……


所以把它放在一起

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spy}
\makeatletter
\e@alloc@luafunction@count=\directlua{tex.print(table.getn(lua.get_functions_table()))}\relax
\makeatother
\usepackage{pst-optexp}
\newsavebox\Lens

\begin{document}
    \savebox\Lens{%%%%<<<<
    \begin{pspicture}
        \pnodes(0,0){A}(3,0){B}
        \pnodes(6.5,0){E}(0.5,0){F}
        \lens[n=1.5,lensheight=2.54,lenswidth=0.9,lensradiusleft=2.264,lensradiusright=0](A)(B){}
        \drawbeam[linecolor=black,beamangle=0,beampos=0,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=blue,beamangle=0,beampos=0.75,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=purple,beamangle=0,beampos=1,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=green,beamangle=0,beampos=-0.75,linewidth=0.6\pslinewidth](F){1}(E)
        \drawbeam[linecolor=yellow,beamangle=0,beampos=-1,linewidth=0.6\pslinewidth](F){1}(E)
        \psline(6.5,-0.25)(6.5,0.25)
    \end{pspicture}%%%%%<<<<<
    }
    \begin{tikzpicture}[spy using outlines={circle,black,magnification=4,size=2cm}]
    \node at (0,0){\usebox\Lens};
  \spy on (-3.3,-5.8) in node at (3,-2);% <-- Issue with this line
    \end{tikzpicture}

\end{document}

我将在 latex2e/base 上提出一个问题,我认为 ltluatex 应该保持 \e@alloc@luafunction@count和 lua 函数表的大小同步。

相关内容