General ⇒ Conditional formatting based upon filename (\jobname)
Conditional formatting based upon filename (\jobname)
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!
------------------------
\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
NEW: TikZ book now 40% off at Amazon.com for a short time.
Conditional formatting based upon filename (\jobname)
The fact that \jobname results in characters with catcode other. See this old thread for more in-depth explanation and solution to your problem.firebush wrote:What am I missing?
Cheers,
Tomek
Conditional formatting based upon filename (\jobname)
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}
Conditional formatting based upon filename (\jobname)
\detokenize works for our environment. Thanks for the immediate response, all!phi wrote:Code: Select all
\ifthenelse{\equal{\detokenize{test}}{\jobname}}{
Brian
Re: Conditional formatting based upon filename (\jobname)
Hi it seems that the solution does not work for jobname like test_123.tex
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Conditional formatting based upon filename (\jobname)
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.bocchi wrote:Hi it seems that the solution does not work for jobname like test_123.tex
Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Conditional formatting based upon filename (\jobname)
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
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
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Conditional formatting based upon filename (\jobname)
So I'm afraid you will have to live with that. Consider to assign proper names to the files in future projects.bocchi wrote:[...] I cannot change the filenames so I'm pretty much stuck [...]
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10