Generalfilename and ifthen

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Meiro
Posts: 1
Joined: Mon Aug 11, 2025 1:02 pm

filename and ifthen

Post by Meiro »

Hi,
I try to check the name of the latexfile with ifthenelse:

Code: Select all

\newcommand{\mydocument}{testfile}
\ifthenelse{\equal{\mydocument}{testfile}}{Test File}{empty mydocument}
\\
\jobname:\\
\ifthenelse{\equal{\jobname}{testfile}}{job: Test File}{empty job}
\\
\currfilename:\\
\ifthenelse{\equal{\currfilename}{testfile.tex}}{cur: testfile}{empty cur}
jobname and currfilename does not work. Any hints?
Thanks a lot
Meiro

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10358
Joined: Mon Mar 10, 2008 9:44 pm

Re: filename and ifthen

Post by Stefan Kottwitz »

An update: this was resolved on TeXwelt.de.

The \ifdefstring command from the etoolbox package is more robust and handles macro expansion better. It works if your file is named TestFile.tex (the online compiler uses an auto-generated filename).

Code: Select all

\documentclass{article}
\usepackage{currfile}
\usepackage{etoolbox}
\begin{document}
currfilename: \currfilename\\
\ifdefstring{\currfilename}{TestFile.tex}{ Bastian Host}{empty currfilename}
\end{document}
Using \currfilename instead of \jobname fixes the issue and should be sufficient.

Stefan
LaTeX.org admin
Post Reply