views:

262

answers:

2

I'm running LaTeX on a named pipe fifo on Unix. I create the fifo like-so:

$ mkfifo fifo

I then run LaTeX like-so:

$ latex fifo

This process blocks and has no output until I write to the fifo from another shell:

$ echo "\\end" > fifo

Then the $ latex fifo output becomes:

This is pdfTeXk, Version 3.1415926-1.40.9 (Web2C 7.5.7)
%&-line parsing enabled.
entering extended mode

However, the LaTeX process never ends. How can you get LaTeX to end? I've tried sending it chr(0) and chr(4) (i.e. ctrl-d), but neither works. Is there some command that will tell LaTeX to exit (i.e. something like \exit)?

Thanks for reading.

EDIT:

It is noteworthy that when you run tex instead of a variant of latex then the following works as expected:

$ echo "story\\end" > fifo

(meanwhile, in the tex console)

$ tex fifo
This is TeX, Version 3.1415926 (Web2C 7.5.7)
(./fifo [1] )
Output written on fifo.dvi (1 page, 212 bytes).
Transcript written on fifo.log.

However, although Leslie Lamport notes in A Document Preparation System LaTeX on page 233 that \end has been replaced by \end{document}, neither of the following ends a LaTeX session:

$ echo "\begin{document}story\end{document}"
$ echo "\\begin{document}story\\end{document}"
+1  A: 

I would suggest allow your shell to direct the fifo pipe to the standard in.

latex < fifo

When I do that, I get this output first:

This is pdfeTeXk, Version 3.141592-1.21a-2.2 (Web2C 7.5.4) (format=latex 2009.3.25)  18 SEP 2009 14:25
entering extended mode
 file:line:error style messages enabled.
 %&-line parsing enabled.

and then after the echo command:

**\end

*
! Emergency stop.
<*> \end

End of file on the terminal!
brianegge
brianegge: Thank you very much for answering -- that definitely works, but it explodes with the -interaction=nonstopmode, and it clutters the logs with e.g. "(Please type a command or say `\end')".
Brian M. Hunt
+1  A: 

If I echo a blank line into the fifo first and then echo the rest of the document, it works fine.

mkfifo test
latex test

Other console:

echo "" > test
echo "\documentclass{report}\begin{document}asdf\end{document}" > test

First console:

xdvi test

My guess is that LaTeX makes two passes of the file whereas TeX does not. On the first pass, LaTeX tries to determine something, then it closes the file, and reopens it for the second pass.

dreamlax
@dreamlax: Thanks for responding. I get the following error when I try that (with xelatex): ! LaTeX Error: Missing \begin{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help. ... l.1 o cumentclass{report}\begin{document}asdf\end{document}
Brian M. Hunt
@dreamlax: I do note that it works fine with regular LaTeX. Boy.
Brian M. Hunt
@Brian: Oh man, sounds like a big web of complicated issues . . . what happens if you echo the same thing twice into xelatex instead of echoing a blank line first?
dreamlax
@Brian: Oh no! I wish I could help you further but what I've offered is the best I can do :(
dreamlax
@dreamlax: No worries! Thank you very much for your input. I'm going to go but the XeTeX people, now. :)
Brian M. Hunt
Does replacing the blank line by a line containing only \relax work better? I seem to recall that some TeX introduction recommended that when you are entering commands interactively.
Jouni K. Seppänen