5

I have very long source text. I want to create two outputs:

  1. All text

  2. Only small pieces of this source text, selected by condition command

MWE (precisely: not working)

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\newif\ifPIECES
\PIECEStrue
\section{Lorem ipsum dolor}
\lipsum[1]

\ifPIECES This is first small piece. I want this piece in two outputs. 
When PIECES is folse, I want all source text. \else\fi

\lipsum[2]

\ifPIECES This is second small piece.  \else\fi

\lipsum[3] 

\ifPIECES This is third small piece.  \else\fi

\lipsum[4]

\end{document}

How I should define LaTeX command? I am nowbe in programming, as you see.

Ama
  • 361
  • 3
    Yes, duplicate. Thank you. But my problem stil stay not solved. : - ( Can I achiewe only PIECES, without signing all source text? – Ama Dec 17 '13 at 13:55
  • You are on the right track, however collect all the else statements in one. This will simplify the code i.e., have only one ifPIECES else statement. – yannisl Dec 17 '13 at 14:09
  • @Yiannis, can you give same example? – Ama Dec 17 '13 at 14:29

1 Answers1

4

Just collect all the else statements together to save on typing and errors, as shown below. Then simply you only need to change one line of the code for the false, i.e., PIECESfalse.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\newif\ifPIECES
\PIECEStrue
\section{Lorem ipsum dolor}
\lipsum[1]

\ifPIECES This is small piece. I want this piece in my PDF, when PIECES is true. 
When PIECES is folse, I want all source text.

This is second small piece. I want second small piece in my PDF, when PIECES is true. When PIECES is folse, I want all source text.

 This is third small piece. I want third small piece in my PDF, when PIECES is true. 
When PIECES is folse, I want all source text.  
\else
    \lipsum[2]
    \lipsum[3] 
    \lipsum[4]
\fi

\end{document}

Second MWE as per comments using a command macro.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\newif\ifPIECES
\PIECESfalse
\section{Lorem ipsum dolor}

\newcommand\twopieces[2]{%
\ifPIECES 
   #1
  \else
    #1#2
\fi
}

\twopieces{This is small piece. I want this piece in my PDF, when PIECES is true. 
   When PIECES is false, I want all source text.}{  \lipsum[2]}


\end{document}
yannisl
  • 117,160
  • @Yannis, thank you. But PIECES text must be interspersed with noPIECES text. I need this for 1. version output - all text. – Ama Dec 17 '13 at 15:13
  • @Ama Will you have a look at the second MWE, if I understood you correctly? This uses a command to save typing the text twice. – yannisl Dec 17 '13 at 15:52
  • @Yannis, thank you for your tip. It works. I will use it for my purposes: -) – Ama Dec 17 '13 at 19:35