6

The following mini example won't compile:

\starttext
\doifundefined{undefined}{%
\startxtable
    \startxtablebody
        \startxrow
            \startxcell cell \stopxcell
        \stopxrow
    \stopxtablebody
\stopxtable}
\stoptext

This is what I get:

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

The same document without \doifundefined compiles just fine and yields the desired output. What can I do to conditionally typeset an xtable?

I am using the latest ConTeXt distribution shipped with texlive 2016.

TeXnician
  • 33,589
LCC
  • 163

1 Answers1

6

xtable are buffers: if you want to embed xtables use \startembeddedxtable instead of \startxtable:

\starttext
 \doifundefined{undefined}{%
 \startembeddedxtable
 \startxtablebody
    \startxrow
        \startxcell cell \stopxcell
    \stopxrow
\stopxtablebody
\stopembeddedxtable
}
\stoptext

Other option is set a mode if a command is undefined and process content according to that mode:

\starttext
\doifundefined{undefined}{\enablemode[alltables]}
\startmode[alltables]
\startxtable
    \startxtablebody
        \startxrow
            \startxcell cell \stopxcell
        \stopxrow
    \stopxtablebody
\stopxtable
\stopmode
\stoptext

or to first store the content of the table in a buffer and process the buffer if the variable is undefined:

\starttext
\startbuffer[content]
\startxtable
    \startxtablebody
        \startxrow
            \startxcell cell \stopxcell
        \stopxrow
    \stopxtablebody
\stopxtable
\stopbuffer
\doifundefined{undefined}{\getbuffer[content]}
\stoptext

(Hans Hagen)

Aditya
  • 62,301
Luigi Scarso
  • 566
  • 2
  • 4