GeneralConditional formatting based upon filename (\jobname)

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
firebush
Posts: 4
Joined: Fri Oct 31, 2008 3:31 pm

Conditional formatting based upon filename (\jobname)

Post by firebush »

Create a file test.tex with the following contents:

------------------------
\documentclass{article}

\usepackage{ifthen}

\begin{document}

\huge
\ifthenelse{\equal{test}{\jobname}}{
good
}{
bad: ``\jobname"
}
\end{document}
------------------------

Run it through pdflatex and notice that the output is bad (literally, it says ``bad: ``test""), but the jobname shows test (what the \equal command is comparing against).

What am I missing? I'm working on a project where we'd like to have different content based upon the jobname. Is this type of thing not possible with \jobname?

Thanks!
Brian

Recommended reading 2024:

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

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

User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Conditional formatting based upon filename (\jobname)

Post by T3. »

firebush wrote:What am I missing?
The fact that \jobname results in characters with catcode other. See this old thread for more in-depth explanation and solution to your problem.

Cheers,

Tomek
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Conditional formatting based upon filename (\jobname)

Post by phi »

The solution there is too complicated (if we can assume that everyone has the eTeX extensions available). This one is simpler:

Code: Select all

\documentclass{article}

\usepackage{ifthen}

\begin{document}

\huge
\ifthenelse{\equal{\detokenize{test}}{\jobname}}{
good
}{
bad: ``\jobname"
}
\end{document}
firebush
Posts: 4
Joined: Fri Oct 31, 2008 3:31 pm

Conditional formatting based upon filename (\jobname)

Post by firebush »

phi wrote:

Code: Select all

\ifthenelse{\equal{\detokenize{test}}{\jobname}}{
\detokenize works for our environment. Thanks for the immediate response, all!
Brian
bocchi
Posts: 4
Joined: Tue Apr 13, 2010 4:47 pm

Re: Conditional formatting based upon filename (\jobname)

Post by bocchi »

Hi it seems that the solution does not work for jobname like test_123.tex
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Conditional formatting based upon filename (\jobname)

Post by localghost »

bocchi wrote:Hi it seems that the solution does not work for jobname like test_123.tex
These difficulties are no surprise since the underscore is reserved for subscripts in math mode. It seems to cause similar problems as in the path and name of external graphics files.


Best regards
Thorsten
bocchi
Posts: 4
Joined: Tue Apr 13, 2010 4:47 pm

Re: Conditional formatting based upon filename (\jobname)

Post by bocchi »

hi
if anyone has got a solution to suggest it will be very much appreciated as I am working on a project and I cannot change the filenames so I'm pretty much stuck
many thanks
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Conditional formatting based upon filename (\jobname)

Post by localghost »

bocchi wrote:[...] I cannot change the filenames so I'm pretty much stuck [...]
So I'm afraid you will have to live with that. Consider to assign proper names to the files in future projects.
Post Reply