Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the file define.tex.

\documentclass{article}
\RequirePackage{changes}
\makeatletter
\@namedef{Changes@AuthorColor}{red}
\colorlet{Changes@Color}{red}
\makeatother
\begin{document}
\ifdefined\submit
submit macro is defined
\else
submit macro is not defined
\fi
\added{if these words are highlighted, this corresponds to draft
  option. not highlighted corresponds to final option}
\end{document}

Inspired by Will's answer to "Passing command-line arguments to LaTeX document", and Martin's answer to "Passing parameters to a document"

I tried

pdflatex   
'\PassOptionsToPackage{final}{changes}\input{define}\def\submit{}\input{define}'    
define.tex

and also

pdflatex
'\def\submit{}\input{define}\PassOptionsToPackage{final}{changes}\input{define}'   
define.tex

In both of these cases, only the first option is seen, as one can check. One would expect the result for both to be "submit macro is defined" with highlighting below, but in fact in one case we get

"submit macro is defined" + highlighting (\def first)

and the other

"submit macro is not defined" + no highlighting (\PassOptionsToPackage first)

This seems like unexpected behavior to me. If I use two similar \defs, there is no problem. I.e. something like

'\def\foo{}\input{define}\def\bar{}\input{define}'

works as expected with the following file.

\documentclass{article}
\begin{document}
\ifdefined\foo
foo macro is defined
\else
foo macro is not defined
\fi
\ifdefined\bar
bar macro is defined
\else
bar macro is not defined
\fi
\end{document}

Ie. the file has

foo macro is defined bar macro is defined

EDIT Aug 21st 2011: I was mistaken about foo and bar. Since \bar was already defined, it was a bad choice. Thanks to T.H. for the clarification and for answering the main question. It seems that if I have a set of options passed to pdflatex like so

pdflatex 'somestuff' 'somemorestuff\input{define}' 'yetmorestuff' [...]

then the 'yetmorestuff' option is not seen by pdflatex. If this is correct, then I don't understand this behavior. T.H. said "The first time you use \input{define}, TeX parses to the end of the file, sees \end{document} and then stops."

However, this is not how option passing normally works. Can someone give me some background on the mechanisms involved here? Thanks.

share|improve this question
    
There is no option passing going on here. You're providing a line of input to TeX. In particular, this is identical to your having written somestuff somemorestuff\input{define} yetmorestuff into a file and then run pdflatex on that file. –  TH. Aug 21 '11 at 8:59
    
@Th.: Thanks for your reply. If TeX simply concatenates lines of input, then wouldn't the commands as above, i.e. pdflatex 'somestuff\input{define}' define.tex have define.tex included twice? This does not seem to be the case. –  Faheem Mitha Aug 21 '11 at 13:02
    
As I already stated, the \end{document} causes TeX to stop reading input. \end{document} (more or less) expands to \enddocument which expands to a bunch of stuff ending with \@@end. \@@end is the TeX primitive \end which causes TeX to stop. –  TH. Aug 25 '11 at 23:43
    
@TH.:Ok, so in the above case, the second define.tex is redundant, right? –  Faheem Mitha Aug 26 '11 at 16:31
    
Yes. The first line of input TeX sees is treated as a file name, unless it begins with a \. That's why pdflatex foo reads foo.tex. You can see this by running pdflatex by itself. It waits for input with a prompt of **. If you enter a file name, it'll typeset it. If you enter something like \relax, then you'll get a prompt * which is treated as the next line of input. –  TH. Aug 28 '11 at 3:55

1 Answer 1

up vote 1 down vote accepted

The first time you use \input{define}, TeX parses to the end of the file, sees \end{document} and then stops.

share|improve this answer
    
But my second (corrected) example (foo, bar) works. Isn't this a counterexample? And if this the problem, what is the remedy? –  Faheem Mitha Aug 15 '11 at 20:48
    
No. \bar is already defined to be \mathaccent "7016\relax. It's doing exactly the same thing. Notice that it only claims that foo macro is defined once, not twice as you would expect if it were actually typesetting define.tex twice. –  TH. Aug 15 '11 at 20:51
    
You're right. I forgot \bar is some math thing. Ok, so what are my options? Can I stick just one \input{define} at the end? Based on a brief test, it looks like that works. Ie. \def\foo{}\def\baz{}\input{define}. –  Faheem Mitha Aug 15 '11 at 20:55
    
I'm not sure what your goal is here. Do you want this typeset twice? If you're just trying to define a few things before \inputting the document, then yes, define it and end with \input. If you're trying to typeset things multiple times with different options, you need to do something else. –  TH. Aug 15 '11 at 20:59
    
Just trying to define a few things before input so I can use it in the text. See my example. Thanks. –  Faheem Mitha Aug 15 '11 at 21:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.