
次のミニ例はコンパイルされません。
\starttext
\doifundefined{undefined}{%
\startxtable
\startxtablebody
\startxrow
\startxcell cell \stopxcell
\stopxrow
\stopxtablebody
\stopxtable}
\stoptext
私が得たものは次のとおりです:
lcc@home:tex> context --batchmode xtable2.tex
resolvers | trees | analyzing '/Users/lcc/Library/texlive/texmf-config'
resolvers | trees | analyzing '/Users/lcc/Library/texlive/texmf'
mtx-context | run 1: luatex --fmt="/Users/lcc/Library/texlive/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luatex/cont-en" --interaction="batchmode" --jobname="xtable2" --lua="/Users/lcc/Library/texlive/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/formats/luatex/cont-en.lui" --no-parse-first-line --c:batchmode --c:currentrun=1 --c:fulljobname="./xtable2.tex" --c:input="./xtable2.tex" --c:kindofrun=1 --c:maxnofruns=9 "cont-yes.mkiv"
This is LuaTeX, Version 0.95.0 (TeX Live 2016)
system commands enabled.
resolvers > trees > analyzing '/Users/lcc/Library/texlive/texmf-config'
resolvers > trees > analyzing '/Users/lcc/Library/texlive/texmf'
open source > 1 > 1 > /usr/local/texlive/current/texmf-dist/tex/context/base/mkiv/cont-yes.mkiv
system > 'cont-new.mkiv' loaded
open source > 2 > 2 > /usr/local/texlive/current/texmf-dist/tex/context/base/mkiv/cont-new.mkiv
close source > 2 > 2 > /usr/local/texlive/current/texmf-dist/tex/context/base/mkiv/cont-new.mkiv
system > files > jobname 'xtable2', input './xtable2', result 'xtable2'
fonts > latin modern fonts are not preloaded
languages > language 'en' is active
open source > 2 > 3 > /Users/lcc/Projects/inactive/MVNECO/tex/xtable2.tex
close source > 2 > 3 > /Users/lcc/Projects/inactive/MVNECO/tex/xtable2.tex
close source > 1 > 3 > /usr/local/texlive/current/texmf-dist/tex/context/base/mkiv/cont-yes.mkiv
tex error > tex error on line 0 in file : ! Emergency stop
<empty file>
mtx-context | fatal error: return code: 1
同じドキュメントを\doifundefined
コンパイルせずに実行しても問題なく、目的の出力が得られます。条件付きで xtable をタイプセットするにはどうすればよいでしょうか?
私はtexlive 2016に同梱されている最新のConTeXtディストリビューションを使用しています。
答え1
xtable はバッファです。xtable を埋め込む場合は、\startembeddedxtable
代わりに以下を使用します\startxtable
。
\starttext
\doifundefined{undefined}{%
\startembeddedxtable
\startxtablebody
\startxrow
\startxcell cell \stopxcell
\stopxrow
\stopxtablebody
\stopembeddedxtable
}
\stoptext
他のオプションは、コマンドが未定義の場合にモードを設定し、そのモードに従ってコンテンツを処理します。
\starttext
\doifundefined{undefined}{\enablemode[alltables]}
\startmode[alltables]
\startxtable
\startxtablebody
\startxrow
\startxcell cell \stopxcell
\stopxrow
\stopxtablebody
\stopxtable
\stopmode
\stoptext
または、まずテーブルの内容をバッファに保存し、変数が未定義の場合はバッファを処理します。
\starttext
\startbuffer[content]
\startxtable
\startxtablebody
\startxrow
\startxcell cell \stopxcell
\stopxrow
\stopxtablebody
\stopxtable
\stopbuffer
\doifundefined{undefined}{\getbuffer[content]}
\stoptext
(ハンス・ハーゲン)