我想编译这个例子:
\setuppapersize[A4]
\usemodule[tikz]
\usetikzlibrary[calc,positioning]
\usemodule[fullpage][style={cm,empty}]
\setupfullpage [margin=0cm]
\usecolors[crayola]
\definecolor[bleu][x=3bbaba]
\starttext
\starttikzpicture[remember picture,overlay]
\draw[bleu,step=2mm](current page.south west) grid (current page.north east);
\stoptikzpicture
\stoptext
main.log文件:
resolvers > globbing > confusing filename, name: 'README.TXT', lower: 'readme.txt', already: 'README.txt'
resolvers > globbing > confusing filename, name: 'README.TXT', lower: 'readme.txt', already: 'README.txt'
resolvers > globbing > confusing filename, name: 'README.TXT', lower: 'readme.txt', already: 'README.txt'
resolvers > globbing > confusing filename, name: 'README.TXT', lower: 'readme.txt', already: 'README.txt'
system >
system > ConTeXt ver: 2023.09.04 19:15 LMTX fmt: 2023.9.5 int: english/english
system >
system > 'cont-new.mkxl' loaded
open source > level 1, order 1, name '/home/aviroum/context/tex/texmf-context/tex/context/base/mkxl/cont-new.mkxl'
system > beware: some patches loaded from cont-new.mkiv
close source > level 1, order 1, name '/home/aviroum/context/tex/texmf-context/tex/context/base/mkxl/cont-new.mkxl'
system > files > jobname './main', input './main.tex', result './main'
fonts > latin modern fonts are not preloaded
languages > language 'en' is active
system > synctex functionality is enabled, expect 5-10 pct runtime overhead!
open source > level 1, order 2, name './main.tex'
open source > level 2, order 3, name '/home/aviroum/context/tex/texmf-context/tex/context/base/mkiv/colo-imp-crayola.mkiv'
close source > level 2, order 3, name '/home/aviroum/context/tex/texmf-context/tex/context/base/mkiv/colo-imp-crayola.mkiv'
colors > system 'crayola' is loaded
open source > level 2, order 4, name '/home/aviroum/context/tex/texmf-context/tex/context/fonts/mkiv/type-imp-texgyre.mkiv'
close source > level 2, order 4, name '/home/aviroum/context/tex/texmf-context/tex/context/fonts/mkiv/type-imp-texgyre.mkiv'
fonts > defining > font 'texgyretermes-regular', feature 'locl', script 'latn', no language 'dflt'
modules > 'tikz' is loaded
open source > level 2, order 5, name '/home/aviroum/context/tex/texmf-context/tex/context/modules/mkxl/m-tikz.mkxl'
open source > level 3, order 6, name 'pgfutil-common.tex'
open source > level 4, order 7, name 'pgfutil-common-lists.tex'
close source > level 4, order 7, name 'pgfutil-common-lists.tex'
close source > level 3, order 7, name 'pgfutil-common.tex'
open source > level 3, order 8, name 'pgfutil-context.def'
close source > level 3, order 8, name 'pgfutil-context.def'
open source > level 3, order 9, name 'pgfrcs.code.tex'
close source > level 3, order 9, name 'pgfrcs.code.tex'
open source > level 3, order 10, name 'pgfsys.code.tex'
open source > level 4, order 11, name 'pgfkeys.code.tex'
open source > level 5, order 12, name 'pgfkeysfiltered.code.tex'
close source > level 5, order 12, name 'pgfkeysfiltered.code.tex'
close source > level 4, order 12, name 'pgfkeys.code.tex'
open source > level 4, order 13, name 'pgf.cfg'
close source > level 4, order 13, name 'pgf.cfg'
Driver file for pgf: pgfsys-pdftex.def
open source > level 4, order 14, name 'pgfsys-pdftex.def'
open source > level 5, order 15, name 'pgfsys-common-pdf.def'
close source > level 5, order 15, name 'pgfsys-common-pdf.def'
close source > level 4, order 15, name 'pgfsys-pdftex.def'
open source > level 4, order 16, name 'main.pgf'
close source > level 4, order 16, name 'main.pgf'
close source > level 3, order 16, name 'pgfsys.code.tex'
open source > level 3, order 17, name 'pgfkeys.code.tex'
close source > level 3, order 17, name 'pgfkeys.code.tex'
open source > level 3, order 18, name 'pgfsyssoftpath.code.tex'
close source > level 3, order 18, name 'pgfsyssoftpath.code.tex'
open source > level 3, order 19, name 'pgfsysprotocol.code.tex'
close source > level 3, order 19, name 'pgfsysprotocol.code.tex'
open source > level 3, order 20, name 'pgfcore.code.tex'
open source > level 4, order 21, name 'pgfmath.code.tex'
open source > level 5, order 22, name 'pgfmathcalc.code.tex'
open source > level 6, order 23, name 'pgfmathutil.code.tex'
close source > level 6, order 23, name 'pgfmathutil.code.tex'
open source > level 6, order 24, name 'pgfmathparser.code.tex'
close source > level 6, order 24, name 'pgfmathparser.code.tex'
open source > level 6, order 25, name 'pgfmathfunctions.code.tex'
open source > level 7, order 26, name 'pgfmathfunctions.basic.code.tex'
close source > level 7, order 26, name 'pgfmathfunctions.basic.code.tex'
open source > level 7, order 27, name 'pgfmathfunctions.trigonometric.code.tex'
close source > level 7, order 27, name 'pgfmathfunctions.trigonometric.code.tex'
open source > level 7, order 28, name 'pgfmathfunctions.random.code.tex'
close source > level 7, order 28, name 'pgfmathfunctions.random.code.tex'
open source > level 7, order 29, name 'pgfmathfunctions.comparison.code.tex'
close source > level 7, order 29, name 'pgfmathfunctions.comparison.code.tex'
open source > level 7, order 30, name 'pgfmathfunctions.base.code.tex'
close source > level 7, order 30, name 'pgfmathfunctions.base.code.tex'
open source > level 7, order 31, name 'pgfmathfunctions.round.code.tex'
close source > level 7, order 31, name 'pgfmathfunctions.round.code.tex'
open source > level 7, order 32, name 'pgfmathfunctions.misc.code.tex'
close source > level 7, order 32, name 'pgfmathfunctions.misc.code.tex'
open source > level 7, order 33, name 'pgfmathfunctions.integerarithmetics.code.tex'
close source > level 7, order 33, name 'pgfmathfunctions.integerarithmetics.code.tex'
close source > level 6, order 33, name 'pgfmathfunctions.code.tex'
close source > level 5, order 33, name 'pgfmathcalc.code.tex'
open source > level 5, order 34, name 'pgfmathfloat.code.tex'
close source > level 5, order 34, name 'pgfmathfloat.code.tex'
close source > level 4, order 34, name 'pgfmath.code.tex'
open source > level 4, order 35, name 'pgfcorepoints.code.tex'
close source > level 4, order 35, name 'pgfcorepoints.code.tex'
open source > level 4, order 36, name 'pgfcorepathconstruct.code.tex'
close source > level 4, order 36, name 'pgfcorepathconstruct.code.tex'
open source > level 4, order 37, name 'pgfcorepathusage.code.tex'
close source > level 4, order 37, name 'pgfcorepathusage.code.tex'
open source > level 4, order 38, name 'pgfcorescopes.code.tex'
close source > level 4, order 38, name 'pgfcorescopes.code.tex'
open source > level 4, order 39, name 'pgfcoregraphicstate.code.tex'
close source > level 4, order 39, name 'pgfcoregraphicstate.code.tex'
open source > level 4, order 40, name 'pgfcoretransformations.code.tex'
close source > level 4, order 40, name 'pgfcoretransformations.code.tex'
open source > level 4, order 41, name 'pgfcorequick.code.tex'
close source > level 4, order 41, name 'pgfcorequick.code.tex'
open source > level 4, order 42, name 'pgfcoreobjects.code.tex'
close source > level 4, order 42, name 'pgfcoreobjects.code.tex'
open source > level 4, order 43, name 'pgfcorepathprocessing.code.tex'
close source > level 4, order 43, name 'pgfcorepathprocessing.code.tex'
open source > level 4, order 44, name 'pgfcorearrows.code.tex'
close source > level 4, order 44, name 'pgfcorearrows.code.tex'
open source > level 4, order 45, name 'pgfcoreshade.code.tex'
close source > level 4, order 45, name 'pgfcoreshade.code.tex'
open source > level 4, order 46, name 'pgfcoreimage.code.tex'
open source > level 5, order 47, name 'pgfcoreexternal.code.tex'
close source > level 5, order 47, name 'pgfcoreexternal.code.tex'
close source > level 4, order 47, name 'pgfcoreimage.code.tex'
open source > level 4, order 48, name 'pgfcorelayers.code.tex'
close source > level 4, order 48, name 'pgfcorelayers.code.tex'
open source > level 4, order 49, name 'pgfcoretransparency.code.tex'
close source > level 4, order 49, name 'pgfcoretransparency.code.tex'
open source > level 4, order 50, name 'pgfcorepatterns.code.tex'
close source > level 4, order 50, name 'pgfcorepatterns.code.tex'
open source > level 4, order 51, name 'pgfcorerdf.code.tex'
close source > level 4, order 51, name 'pgfcorerdf.code.tex'
close source > level 3, order 51, name 'pgfcore.code.tex'
open source > level 3, order 52, name 'pgffor.code.tex'
open source > level 4, order 53, name 'pgfmath.code.tex'
close source > level 4, order 53, name 'pgfmath.code.tex'
close source > level 3, order 53, name 'pgffor.code.tex'
open source > level 3, order 54, name 'pgfmoduleplot.code.tex'
close source > level 3, order 54, name 'pgfmoduleplot.code.tex'
open source > level 3, order 55, name 'tikz.code.tex'
open source > level 4, order 56, name 'pgflibraryplothandlers.code.tex'
close source > level 4, order 56, name 'pgflibraryplothandlers.code.tex'
open source > level 4, order 57, name 'pgfmodulematrix.code.tex'
open source > level 5, order 58, name 'pgfmoduleshapes.code.tex'
close source > level 5, order 58, name 'pgfmoduleshapes.code.tex'
close source > level 4, order 58, name 'pgfmodulematrix.code.tex'
open source > level 4, order 59, name 'tikzlibrarytopaths.code.tex'
close source > level 4, order 59, name 'tikzlibrarytopaths.code.tex'
close source > level 3, order 59, name 'tikz.code.tex'
open source > level 3, order 60, name 'pgfmoduleplot.code.tex'
close source > level 3, order 60, name 'pgfmoduleplot.code.tex'
open source > level 3, order 61, name 'pgfmoduledecorations.code.tex'
close source > level 3, order 61, name 'pgfmoduledecorations.code.tex'
close source > level 2, order 61, name '/home/aviroum/context/tex/texmf-context/tex/context/modules/mkxl/m-tikz.mkxl'
open source > level 2, order 62, name 'tikzlibrarycalc.code.tex'
close source > level 2, order 62, name 'tikzlibrarycalc.code.tex'
open source > level 2, order 63, name 'tikzlibrarypositioning.code.tex'
close source > level 2, order 63, name 'tikzlibrarypositioning.code.tex'
modules > 'fullpage' is loaded
open source > level 2, order 64, name '/home/aviroum/context/tex/texmf-modules/t-fullpage/tex/context/third/fullpage/t-fullpage.mkiv'
loading > ConTeXt User Module / Fullpage
close source > level 2, order 64, name '/home/aviroum/context/tex/texmf-modules/t-fullpage/tex/context/third/fullpage/t-fullpage.mkiv'
tex error > tex error on line 62 in file ./main.tex: Control sequence expected instead of undefined
<argument>
\hoffset
<macro> \pgfqpoint
#1#2->\global \pgf@x =#1
\relax \global \pgf@y =#2\relax
<macro> \pgf@process
#1->{#1
\global \pgf@x =\pgf@x \global \pgf@y =\pgf@y }
<macro> \pgf@shape@interpictureshift
...gfpictureid }\pgf@shape@current@pos \pgf@xa =\pgf@x \pgf@ya =\pgf@y \pgf@process {\pgfpointorigin \pgf@shape@current@pos }\advance \pgf@xa by-\pgf@x \advance \pgf@ya by-\pgf@y \pgf@process {\pgfpointorigin \pgf@shape@original@pos }
\advance \pgf ...
<argument>
...\csname pgf@sh@ns@\tikz@pp@name {current page}\endcsname }{south west}{\pgfsettransform {\csname pgf@sh@nt@\tikz@pp@name {current page}\endcsname }\pgf@pos@transform@glob }\pgf@shape@interpictureshift {\tikz@pp@name {current page}}
\pgftransform ...
<macro> \pgf@process
#1->{#1
\global \pgf@x =\pgf@x \global \pgf@y =\pgf@y }
...
<line 3.62>
\draw[bleu,step=2mm](current page.south west)
grid (current page.north east);
52
53
54 %OOOOOOOOOOOOOOOOOOOOO
55 %OOOOOOOOOOOOOOOOOOOOO
56 \starttext
57 %OOOOOOOOOOOOOOOOOOOOO
58 %OOOOOOOOOOOOOOOOOOOOO
59
60
61 \starttikzpicture[remember picture,overlay]
62 >> \draw[bleu,step=2mm](current page.south west) grid (current page.north east);
63 \stoptikzpicture
64
65
66
67
68 \stoptext
69 %OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
You injected something that confused the parser, maybe by using some Lua call.
主错误日志:
return {
["errortype"]=0,
["filename"]="./main.tex",
["lastcontext"]="\n<argument> \n \\hoffset \n<macro> \\pgfqpoint \n #1#2->\\global \\pgf@x =#1\n \\relax \\global \\pgf@y =#2\\relax \n<macro> \\pgf@process \n #1->{#1\n \\global \\pgf@x =\\pgf@x \\global \\pgf@y =\\pgf@y }\n<macro> \\pgf@shape@interpictureshift \n ...gfpictureid }\\pgf@shape@current@pos \\pgf@xa =\\pgf@x \\pgf@ya =\\pgf@y \\pgf@process {\\pgfpointorigin \\pgf@shape@current@pos }\\advance \\pgf@xa by-\\pgf@x \\advance \\pgf@ya by-\\pgf@y \\pgf@process {\\pgfpointorigin \\pgf@shape@original@pos }\n \\advance \\pgf ...\n<argument> \n ...\\csname pgf@sh@ns@\\tikz@pp@name {current page}\\endcsname }{south west}{\\pgfsettransform {\\csname pgf@sh@nt@\\tikz@pp@name {current page}\\endcsname }\\pgf@pos@transform@glob }\\pgf@shape@interpictureshift {\\tikz@pp@name {current page}}\n \\pgftransform ...\n<macro> \\pgf@process \n #1->{#1\n \\global \\pgf@x =\\pgf@x \\global \\pgf@y =\\pgf@y }\n ...\n\n<line 3.62> \n \\draw[bleu,step=2mm](current page.south west)\n grid (current page.north east);\n\n",
["lastluaerror"]="",
["lasttexerror"]="Control sequence expected instead of undefined",
["lasttexhelp"]="You injected something that confused the parser, maybe by using some Lua call.",
["linenumber"]=62,
["offset"]=10,
["skiplinenumber"]=62,
}
是否有任何指南可以解释类似乳胶中的错误。
提前致谢
答案1
第一个问题是由于缺少\hoffset
和 的定义\voffset
。请参阅Aditya 的回答了解更多信息。
这里的第二个问题是,由于一些内部操作,Lua 端\lastxpos
是整数,而\lastypos
是浮点数。当将其发送到 TeX 时,它看到的内容如下:
\numexpr 12345\relax % \lastxpos
\numexpr 123.5\relax % \lastypos
\numexpr
在第一个不可扩展或非数字标记之后停止扩展。对于\lastxpos
,那是\relax
(它会扩展为零并消失);但对于\lastypos
,那是小数点(.
),因此\relax
末尾的 留在标记流中。
ConTeXt 开发人员已经承认了这一点,所以最好的解决方案是等到下一次更新。
或者,您可以使用这个临时解决方法:
% See Aditya's answer
\newdimen\hoffset
\newdimen\voffset
% \last[xy]pos fix:
\startluacode
interfaces.implement {
name = "lastxpos",
actions = function() context("%.0f", job.positions.lastx) end
}
interfaces.implement {
name = "lastypos",
actions = function() context("%.0f", job.positions.lasty) end
}
\stopluacode
% Original, unmodified code:
\setuppapersize[A4]
\usemodule[tikz]
\usetikzlibrary[calc,positioning]
\usemodule[fullpage][style={cm,empty}]
\setupfullpage [margin=0cm]
\usecolors[crayola]
\definecolor[bleu][x=3bbaba]
\starttext
\starttikzpicture[remember picture,overlay]
\draw[bleu,step=2mm](current page.south west) grid (current page.north east);
\stoptikzpicture
\stoptext
答案2
编辑:此问题已在上下文版本中修复2023.09.17 09:30
这是一个很长的评论,用来解释发生了什么。
首先,\hoffset
和\voffset
在 ConTeXt 中没有定义。我不知道它们在 LaTeX 中应该代表什么,但我们只需添加它们的定义即可。(我还从示例中删除了所有不必要的代码)。
\newdimen\hoffset
\newdimen\voffset
\usemodule[tikz]
\starttext
\starttikzpicture[remember picture,overlay]
\draw(current page.south west) grid (current page.north east);
\stoptikzpicture
\stoptext
第一次编译时运行正常。第二次运行出现错误:
tex error > tex error on line 7 in file ./test.tex: Illegal unit of measure (pt inserted)
<to be read again>
\relax
<argument>
46204089.0\relax
sp
<macro> \pgfqpoint
#1#2->\global \pgf@x =#1\relax \global \pgf@y =#2
\relax
<macro> \pgf@process
#1->{#1
\global \pgf@x =\pgf@x \global \pgf@y =\pgf@y }
<macro> \pgf@shape@interpictureshift
...id \else \pgfsys@getposition {\csname pgf@sh@pi@#1\endcsname }\pgf@shape@original@pos \pgfsys@getposition {\pgfpictureid }\pgf@shape@current@pos \pgf@xa =\pgf@x \pgf@ya =\pgf@y \pgf@process {\pgfpointorigin \pgf@shape@current@pos}
\advance \pgf ...
<argument>
...\csname pgf@sh@ns@\tikz@pp@name {current page}\endcsname }{south west}{\pgfsettransform {\csname pgf@sh@nt@\tikz@pp@name {current page}\endcsname }\pgf@pos@transform@glob }\pgf@shape@interpictureshift {\tikz@pp@name {current page}}
\pgftransform ...
...
<line 3.7>
\draw(current page.south west)
grid (current page.north east);
1 \newdimen\hoffset
2 \newdimen\voffset
3 \usemodule[tikz]
4
5 \starttext
6 \starttikzpicture[remember picture,overlay]
7 >> \draw(current page.south west) grid (current page.north east);
8 \stoptikzpicture
9
10 \stoptext
11
出现此错误的原因是 TikZ 写入了一个\jobname.pgf
包含以下内容的文件:
\pgfsyspdfmark {pgfid1}{4661756}{46204089.0\relax }
\relax
注意最后的额外内容。读取此文件时,TikZ 会尝试调用宏:
\def\pgfsyspdfmark#1#2#3{%
\expandafter\gdef\csname pgf@sys@pdf@mark@pos@#1\endcsname{\pgfqpoint{#2sp}{#3sp}}%
\pgfutil@check@rerun{#1}{{#2}{#3}}%
}
46204089.0\relax sp
由于尺寸无效,因此会导致错误。
我不明白为什么\relax
要将其写入 pgf 文件。写入内容的代码是:
\def\pgfsys@markposition#1{%
\savepos%
\edef\pgf@temp{#1}%
\expandafter\pgfutil@writetoaux\expandafter{%
\expandafter\noexpand\expandafter\pgfsyspdfmark\expandafter{\pgf@temp}{\the\lastxpos}{\the\lastypos}}%
}
这不是扩展问题。不知何故,它的\lastypos
行为与 不同\lastxpos
(如果我更改两个命令的顺序,即使如此, 也是\relax
与 一起的ypos
。
答案3
虽然这个问题在最新版本中已经修复,但我还是发布了另一个答案来展示如何在不使用的情况下实现相同的结果remember picture
。当然,ConTeXtish 解决方案是使用 MetaPost,但我们不必这样做。
ConTeXt 有这个很好的功能调用覆盖基本上,您可以在覆盖层中放置任何您想要的东西(包括 tikzpicture!)。
\usemodule[tikz]
\usecolors[crayola]
\definecolor[bleu][x=3bbaba]
\startsetups tikz:grid
\starttikzpicture
\draw[bleu,step=2mm] (0,0) grid (\overlaywidth,\overlayheight);
\stoptikzpicture
\stopsetups
\defineoverlay
[background:grid]
[\setups{tikz:grid}]
\setupbackgrounds[page][background=background:grid]
\starttext
\input ward
\stoptext
这个解决方案的优点在于它不仅适用于页面背景,还适用于任何有关键内容的内容background
。例如:
\startframedtext[background=background:grid]
\input ward
\stopframedtext