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.

5

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)

  • (+1) I have no idea what a buffer is, but it sounds suitably TeXnical. – cfr Jun 12 '16 at 20:12
  • 1
    @cfr: See my question on LaTeX equivalent of ConTeXt buffers; in particular, Taco Hoekwater's answer. The key advantage of buffers (over macros) is that buffers ignore catcodes (similar to a verbatim environment). – Aditya Jun 12 '16 at 23:13
  • @LuigiScarso: I added another option in your answer; hope that you don't mind. – Aditya Jun 12 '16 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.