如何创建虚拟通用环境替代品?

如何创建虚拟通用环境替代品?

我正在尝试创建一个调试模式,这样我就可以注释掉文档中的大多数内容。现在我能够用 替换诸如\currenttimefrom datetimepackage 之类的命令\def\currenttime{Current Time}

但是当我尝试为环境创建通用替代品时,longtable我无法成功创建虚拟环境。这样做:

\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}

抛出这些错误:

! 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.

目前我认为虚拟环境可以将其内容输出为纯文本或根本不显示任何内容。是否可以修复它以替换任何环境,而不管参数数量或其内容如何?


有关的:

  1. 具有虚拟参数的环境
  2. 定义接受参数的环境
  3. 使用一个可选参数创建新环境
  4. 如何打造“延迟扩展”环境?
  5. 是否有通用的虚拟命令?

答案1

如果您想要某种“无论内容如何”都能正常工作的东西,那么您将需要某种类型的逐字环境:

\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]

如果内容消失,请检查评论包。

答案2

您应该将 cat 代码更改&为“其他”(12)。如果不这样做,&这将是 LaTeX 无法在表格之外处理的对齐字符。

旁注:您不应将其更改为“字母”(11),因为这样 LaTeX 代码\mycell&就会出现错误(&将成为宏名称的一部分)。

\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}

相关内容