GeneralInsert output of a shell command into LaTeX file at compile?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Insert output of a shell command into LaTeX file at compile?

Post by bombcar »

I want to be able to have a LaTeX file automatically show the revision number. So basically, in the file have something like

File Revision {bzr revno}

And make it so when LaTeX is run it will replace {bzr revno} with the output of that command (in this case 12). Is there a way to do this? I don't want to actually edit the file because then it would need to be checked in again.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Insert output of a shell command into LaTeX file at compile?

Post by bombcar »

I got partially there by using:

Code: Select all

This is revision \input{revision.txt}.
And then having my Makefile run bzr revno > revision.txt first. But this puts an extra space after the \input command, and I get:

This is revision 193 .
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Insert output of a shell command into LaTeX file at compile?

Post by phi »

You have to change \endlinechar to avoid the space:

Code: Select all

\documentclass{article}

\newcommand*\Revision{%
	\edef\RestoreEndlinechar{\endlinechar=\the\endlinechar\relax}%
	\endlinechar=-1 %
	\input{revision.txt}%
	\RestoreEndlinechar
}

\begin{document}
Revision \Revision.
\end{document}
pdfTeX can also execute shell commands if that facility is enabled on the command line. Then you can say

Code: Select all

\input "|bzr revno"
Subversion users prefer using properties (special strings that get replaced automatically during each commit operation). Perhaps Bazaar provides a similar facility.
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Re: Insert output of a shell command into LaTeX file at compile?

Post by bombcar »

Thanks! The first one worked great. Unfortunately, it doesn't look like Bazaar supports anything like the "properties."
Post Reply