0

I am trying to create a debug mode where I can comment out most things on the document. For now I was able to replace commands like \currenttime from datetime package with \def\currenttime{Current Time}.

But when I tried to create a generic replacement for a environment as longtable I could not create successfully a dummy environment. Doing:

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}

\newif\ifdebug
\debugtrue
% \debugfalse

\ifdebug
    \def\hline{hline}
    \def\RaggedRight{RaggedRight}

    \newenvironment{longtable}[2]
        {longtable environment}
        {replacement for debug mode}
\else\fi

\begin{document}
\begin{longtable}[!ht]{ | >{\RaggedRight}p{3cm} | p{6cm} | }

        \hline
        Cor                          & Branco  \\ \hline
        Formato do papel             & A5      \\ \hline

\end{longtable}
\end{document}

Throw these errors:

! Misplaced alignment tab character &.
l.93         Cor                          &
                                            Branco  \\ \hline
I can't figure out why you would want to use a tab mark
here. If you just want an ampersand, the remedy is
simple: Just type `I\&' now. But if some right brace
up above has ended a previous alignment prematurely,
you're probably due for more error messages, and you
might try typing `S' now just to see what is salvageable.

! Misplaced alignment tab character &.
l.94         Formato do papel             &
                                            A5      \\ \hline
I can't figure out why you would want to use a tab mark
here. If you just want an ampersand, the remedy is
simple: Just type `I\&' now. But if some right brace
up above has ended a previous alignment prematurely,
you're probably due for more error messages, and you
might try typing `S' now just to see what is salvageable.

For now I think the dummy environment could just output its contents as plain text or not display anything at all. Can it be fixed for replacing any environment, independent of the number of parameters or its contents?


Related:

  1. Environment with a dummy parameter
  2. Defining an Environment that Takes an Argument
  3. Creating a new environment with one optional argument
  4. How to create a "delay expansion" environment?
  5. Is there a generic dummy command?
3
  • You have to change the cat code of & in the best case (to something like 12).
    – TeXnician
    Aug 20, 2017 at 18:04
  • @TeXnician Thanks! I used \catcode\@=11` and it compiled successfully: en.wikibooks.org/wiki/TeX/catcode
    – user
    Aug 20, 2017 at 18:10
  • Well, you should not use 11 as a & should never appear within a macro name (for example). 12 seems more appropriate.
    – TeXnician
    Aug 20, 2017 at 18:11

2 Answers 2

2

If you want something that works "regardless of the content" you will need some type of verbatim environment:

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}
\usepackage{verbatim}
\newif\ifdebug
\debugtrue
% \debugfalse

\ifdebug
    \def\hline{hline}
    \def\RaggedRight{RaggedRight}

    \newenvironment{longtable}[2][]
        {longtable environment\par\verbatim}
        {\endverbatim \endgraf replacement for debug mode}
\else\fi

\begin{document}
\begin{longtable}[!ht]{ | >{\RaggedRight}p{3cm} | p{6cm} | }

        \hline
        Cor                          & Branco  \\ \hline
        Formato do papel             & A5      \\ \hline

\end{longtable}
\end{document}

[![enter image description here][1]][1]

If the content should disappear check the comment package.

2
  • The verbatim is causing Overfull \hbox (17.92822pt too wide) in paragraph at lines, can its contents be auto wrapped?
    – user
    Aug 20, 2017 at 18:35
  • 2
    You can use a listings environment instead of verbatim, check its documentation about how to define new listingsenvironments. Or use simply a tiny font -- for debug mode it should be good enough. Aug 20, 2017 at 18:38
2

You should change the cat code of & to a "other" (12). If you don't do that & will be an alignment character which LaTeX cannot treat outside of tables.

Side note: You should not change it to "letter" (11) as then LaTeX code like \mycell& will give an error (the & will be part of the macro name).

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}

\newif\ifdebug
\debugtrue
%\debugfalse

\ifdebug
    \def\hline{hline}
    \def\RaggedRight{RaggedRight}

    \newenvironment{longtable}[2][]
        {\catcode`&=12 longtable environment}
        {\catcode`&=4 replacement for debug mode}
\else\fi

\begin{document}
\begin{longtable}[!ht]{ | >{\RaggedRight}p{3cm} | p{6cm} | }
        \hline
        Cor                          & Branco  \\ \hline
        Formato do papel             & A5      \\ \hline
\end{longtable}
\end{document}

You must log in to answer this question.

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