Using pgfkeys I wrote some macros to do something more general than this. As that question has been closed I will reproduce it here.
Using my code you can type your different language sections using the environment SelectEnvironment
, tagging it as either Chinese or English:
\begin{SelectEnvironment}[English]
English paragraph 1 goes here.
\end{SelectEnvironment}
\begin{SelectEnvironment}[Chinese]
Chinese paragraph 1 goes here. % this is pretend Chinese.
\end{SelectEnvironment}
Then you can selectively print choose one or both languages by putting one of the following lines at the top of your document:
\SelectCommentsToPrint{all} % both languages
\SelectCommentsToPrint{Englsh} % English only
\SelectCommentsToPrint{Chinese} % Chinese only
You can also use \SelectCommentsToPrint
anywhere in the document to add to the list of comments being printed. There is "unset" feature to turn off printing of one language, say:
\SelectCommentsToPrint{unset/Englsh} % stop printing English
Here is a MWE:
\documentclass{article}
\usepackage{pgf,pgffor}
\usepackage{environ}
\usepackage{amsmath}
\usepackage{xcolor}% only needed for highlighting selections in MWE
% https://tex.stackexchange.com/questions/15204/is-there-a-way-to-set-a-global-key-value-using-pgfkeys
\makeatletter
\newcommand{\pgfkeysgsetvalue}[2]{\pgfkeys@temptoks{#2}\expandafter\xdef\csname pgfk@#1\endcsname{\the\pgfkeys@temptoks}}
\makeatother
\pgfkeys{/SelectiveComment/.is family,/SelectiveComment,
set/.unknown/.code={
\pgfkeysgsetvalue{/SelectiveComment/\pgfkeyscurrentname}{1}
},
set/unset/.unknown/.code={
\pgfkeysgsetvalue{/SelectiveComment/\pgfkeyscurrentname}{0}
}
}
\newif\ifPrintComment% print comment if true
\newcommand\SelectCommentsToPrint[1]{%
\foreach \key in {#1}{\pgfkeys{/SelectiveComment,set/\key} }
}
\newcommand\MakeSelection[1]{
\PrintCommentfalse% comments off by default
\foreach \key in {#1,all} {
\pgfkeysifdefined{/SelectiveComment/\key}%
{\pgfkeysgetvalue{/SelectiveComment/\key}{\temp}
\ifnum\temp=1\global\PrintCommenttrue\fi% print if key=1
}{}
}
}
\newcommand\Select[2][]{\MakeSelection{#1}\ifPrintComment#2\fi}
\NewEnviron{SelectEnvironment}[1][]{\MakeSelection{#1}\ifPrintComment\BODY\fi }
\begin{document}
\SelectCommentsToPrint{all}
\begin{SelectEnvironment}[English]
English paragraph 1 goes here.
\end{SelectEnvironment}
\begin{SelectEnvironment}[Chinese]
Chinese paragraph 1 goes here. % this is pretend Chinese.
\end{SelectEnvironment}
\[ \text{Formula 1.}\]
\begin{SelectEnvironment}[English]
English paragraph 1 goes here.
\end{SelectEnvironment}
\begin{SelectEnvironment}[Chinese]
Chinese paragraph 1 goes here. % this is pretend Chinese.
\end{SelectEnvironment}
\end{document}
The MWE produces:

If I change the \SelectCommentsToPrint{all}
to \SelectCommentsToPrint{Chinese}
then the output is:

There is also a \Select
command for printing shorter sections of text. It is used in the same way:
\Select[Chinese]{Some more words pretending to be Chinese}
With both \Select
and the SelectEnvironment
you can also specify that the text should be printed in both languanges:
\Select[Chinese,English]{Will be printed when either Chinese or English is selected.}
Finally, I should note that with this code you can use arbitrary keys: they don't have to be Chinese
and English