2

Answer below

Issue

I am using the package xifthen to try and check if a string variable is equal to a specific string in order to input something. I only want to do something in case the test is validated, meaning no else.

i.e. \ifthenelse{<test>}{true}{}

When testing the string against an integer (e.g. \equal{string}{1}), it works as expected. However, when checking against a string (e.g. \equal{string}{test}) it breaks if no value is set for the else part.

[Edit] Here is the error message I get: error message The document does compile if I build it at least twice, but fails the first time.

Question

Why is that so? How can I fix it or find a workaround?

MWE

\documentclass{article}
\usepackage{mwe}
\usepackage{xifthen}
\begin{document}
\ifthenelse{\equal{string}{1}}{1}{}
\smallbreak
\ifthenelse{\equal{string}{test}}{true}{}
\end{document}

Edit & answer

The MWE does not output anything which makes latexmk crash. By outputing one thing before or after, it works as expected.

Akaizoku
  • 608
  • 1
    Not tested but try \ifthenelse{\equal{string}{test}}{true}{\relax}. What does \relax do? – Chris H Mar 13 '17 at 14:44
  • @ChrisH Sadly, it does not fix the issue. – Akaizoku Mar 13 '17 at 14:50
  • Your MWE works as expected. However, you probably don't intend for string and test to be literals, but rather some macro or something?? Please clarify. – Steven B. Segletes Mar 13 '17 at 14:59
  • @StevenB.Segletes I added the error message that I get. My document does not compile as is. – Akaizoku Mar 13 '17 at 15:02
  • The example posted does not produce an error. – David Carlisle Mar 13 '17 at 15:10
  • by "my document" do you mean if you use the example here you get an error? if so, please add the full log file to your question so we can compare. – David Carlisle Mar 13 '17 at 15:10
  • @DavidCarlisle I am working with the exact MWE. I get an error each time I build for the fist time. I added the log to the initial post. – Akaizoku Mar 13 '17 at 16:38
  • 1
    There is no error shown in the log that you posted. But there is no pdf output either (as it doesn't make any output) perhaps latexmk was not expecting that. – David Carlisle Mar 13 '17 at 16:50
  • The cause of the problem is that your MWE doesn't write any output at all to the PDF. In that situation pdftex doesn't create an "empty" PDF (whatever that means in real life). It doesn't create a .pdf file at all. latexmk then fails, because the LaTeX run apparently worked (no errors on the log file) but it can't find the .pdf to check if it needs to run pdftex again to resolve cross-references properly, etc. This is arguably a bug, but not a very interesting one since almost any non-minimal example will produce some output in the PDF, even if it is complete garbage! – alephzero Mar 14 '17 at 04:27
  • @alephzero Oh, I see. I actually made a mistake in my code which led me to believe it was due to my misunderstanding of the process. Everything is working as expected indeed, thank you guys for your time. – Akaizoku Mar 14 '17 at 11:35
  • 4
    I'm voting to close this question as off-topic because the issue is due to latexmk not recognizing that no pdf file has been produced – egreg Mar 14 '17 at 12:56

0 Answers0