1

I am trying to set up a new environment using xparse and its \NewDocumentEnvironment including a table.

My MWE looks like this:

\documentclass{article}

\usepackage{tabularx}
\usepackage{xparse}

\NewDocumentEnvironment{\testtable}{m}
    {%
    \table%
        \tabularx{\textwidth}{#1}%
    }%
    {%
        \endtabularx%
    \endtable%
}

\begin{document} 

 \begin{testtable}{ccc}
  0 & 0 & 0 \\
  1 & 0 & 1 \\
  2 & 1 & 0 \\
  3 & 1 & 1
 \end{testtable}

\end{document}

Compiling fails with

14:Undefined conrol sequence }

with line 14, being the closing '}' of my environment.

I stripped the example as much as possible, to make it work, but it doesn't compile.

What's wrong here?

6
  • Erh, isn't this just an error 40 (the error that is 40 cm from the screen)? Replace \texttable by testtable, then this compiles just fine.
    – daleif
    Jun 26, 2018 at 12:45
  • BTW: why are you using tabularx in this case when you are not using the X columns?
    – daleif
    Jun 26, 2018 at 12:47
  • \NewDocumentEnvironment{testtable}{m} {% \table% \tabularx{\textwidth}{#1}% }% {% \endtabularx% \endtable% } Jun 26, 2018 at 12:48
  • you have to have at least one X column if you want tabularx to do anything useful. Jun 26, 2018 at 12:50
  • Note that tex's error message is not as you show it is much clearer: ! Undefined control sequence. <argument> \testtable If your editor is just showing the corrupted form of the error message that you showed then that is a mis-feature of the editor, which you should report. Jun 26, 2018 at 12:53

2 Answers 2

1
\NewDocumentEnvironment{testtable}{m}
    {%
    \table%
        \tabularx{\textwidth}{#1}%
    }%
    {%
        \endtabularx%
    \endtable%
}

Use like above

0
0

The MWE compiles just fine, if you replace

\NewDocumentEnvironment{\testtable}{m}

by

\NewDocumentEnvironment{testtable}{m}

after all, it is an environment you are creating, not a mere macro.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .