Embedding version control information returns error when file is not under version control

Consider the following MWE. Note that this uses Mercurial for illustrative purposes, but the question is not specific to Mercurial

\documentclass{article}
\usepackage{fouriernc}
\begin{document}

\parbox{\linewidth}{\centering
\input{"| hg log -v -l 1 \jobname.tex --template '{node}  {date|isodate}'"}\\
}
\end{document}


If the file is under version control, then the command

hg log -v -l 1 \jobname.tex --template '{node}  {date|isodate}'


has a non-empty value, and then there is no problem. However, if the file is under version control, then this command does not return a value, and the file reduces to

\documentclass{article}
\usepackage{fouriernc}
\begin{document}

\parbox{\linewidth}{\centering
\\
}
\end{document}


which gives an error. What is a good way of ensuring that if the string returned by input is empty, then the \\ should be removed?

A different command could be used instead of the hg one. The only requirement is that under some conditions it return nothing.

• What it the hg tag for? – karlkoeller Mar 30 '15 at 6:59
• @karlkoeller See update. – Faheem Mitha Mar 30 '15 at 6:59
• @karlkoeller what is the rationale for indenting the code 8 spaces instead of 4? – Faheem Mitha Mar 30 '15 at 7:10
• I don't know. It's you that are indenting it with 8 spaces (it is needed when inside a list, but not here) – karlkoeller Mar 30 '15 at 7:15
• Best would not be to use \\  at all and just have a blank line. Or the end of the \parbox if there really is nothing following. – David Carlisle Apr 10 '16 at 15:17

You could test for hmode:

\documentclass{article}
\usepackage{fouriernc}
\begin{document}

\parbox{\linewidth}{\centering
% your input ...
\ifhmode  \\  \fi
blalal
}
\end{document}

• This works, but I don't know why. Apparently % your input is processed if TeX is in one of the horizontal modes, and otherwise is ignored. But why does blank input imply that it leaves horizontal mode? – Faheem Mitha Apr 9 '16 at 21:41
• @FaheemMitha: the "%your comment" is only a comment, I left out your command as it is not relevant. – Ulrike Fischer Apr 9 '16 at 21:44
• Sorry, I've no idea what your comment is saying. I'm in chat, if you prefer to answer there. – Faheem Mitha Apr 9 '16 at 21:46
• I simply added a test around the  \\  which checks if the paragraph has already started. – Ulrike Fischer Apr 9 '16 at 21:47