5

I'm translating some text that use the comment package, it's usage seems like that:

\begin{en}
 ... some English text
\end{en}

\begin{zh}
... corresponding Chinese text
\end{zh}

By using \excludecommand{en} or \includecommand{en} before \begin{document}, we can control the text out or in the final PDF document.

But this too trouble to add \begin{}/\end{} for every paragraph, what I want is following:

\en{
 ... some English text
}

\zh{
... corresponding Chinese text
}

this is much more simple to type. and I create the commands like this:

\newcommand{\zh}[1]{\begin{zh}#1\end{zh}}
\newcommand{\en}[1]{\begin{en}#1\end{en}}

But this cause compile error like runaway argument, how to make it work under this situation by using newcommand?

coanor
  • 535
  • You can try \let\OldEn\en and use \OldEn, instead of \begin{en} and \enden, instead of \end{en}. Also, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that reproduces the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Mar 19 '14 at 14:18
  • I think the best way to do things would be to keep the environments and to configure your editor so that with a shortcut it typesets the environment and puts the cursor in the middle. – Bernard Mar 19 '14 at 14:27
  • 1
    Note that not all environments can be turned into commands (anything with verbatim or ams alignments will cause trouble at least) also in a large document it is a lot easier to see matching begin/end than working out what is ended by } any reasnobel editor shoudl allow you to enter \begin{en} \end{en} with 1 or 2 keystrokes – David Carlisle Mar 19 '14 at 14:28
  • 1
    You can't: The comment environment is looking for the string \end{en} while skipping over the rest of the text. Also it is problematic to put large portions of text in an argument: You can't change catcodes there and so a lot of things (e.g. verbatim) are not possible. – Ulrike Fischer Mar 19 '14 at 14:29
  • @Bernard: what I'm planning is sed or awk... – coanor Mar 19 '14 at 14:29
  • note that it's \includecomment and \exclude.... 2. your runaway arguments are because you have an end-paragraph (double-\n) inside the command argument; use \newcommand* instead of just \newcommand ... or keep to 1 paragraph per \en or \zh command, and have the paragraph breaks outside the commands
  • – wasteofspace Mar 19 '14 at 15:30