GeneralRecovery of Value by Condition

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
leo simon
Posts: 17
Joined: Wed Aug 19, 2009 5:41 pm

Recovery of Value by Condition

Post by leo simon »

Hi,

I'm trying to condition on the current directory using the "currfile-abspath" package from currfile by means of ifthen. The command \getpwd does recover the pwd, but for some reason I can't condition on the value of \thepwd using ifthen. The problem seems to be with the ifthen command, since I *can* condition on the value of \currfilepath so long as I use the provided \ifcurrfilepath, but *not* if I use an ifthen statement.


Here's an example.

Code: Select all

\documentclass{amsart}
\usepackage{currfile}
\usepackage{currfile-abspath}
\usepackage{ifthen}

\begin{document}
\getpwd

The current file name is \currfilepath

Pwd is set to \thepwd

\ifcurrfilepath{testCurrfile.tex}
    {The current filename is \currfilepath}
    {Apparently the current filename is not \currfilepath}

\ifthenelse{\equal{\currfilepath}{testCurrfile.tex}}
    {The current filename is \currfilepath}
    {Apparently the current filename is not \currfilepath}

\ifthenelse{\equal{\thepwd}{/tmp}}
    {The current directory is \thepwd}
    {Apparently the current directory is not \thepwd}


\end{document}

If I run this from, say, /tmp, (I'm using Linux) then \thepwd correctly returns /tmp/ but the ifthen conditional fails. Also the \ifcurrfilepath returns true, but the \equal{\currfilepath}{testCurrfile.tex} returns false.



Any advice would be most appreciated, Thanks

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am

Recovery of Value by Condition

Post by tom »

Hi!

It seems \equal only works with numbers. Use \pdf@strcmp instead (pdftexcmds).

Code: Select all

%Preamble
\usepackage[abspath]{currfile}
\usepackage{ifthen, pdftexcmds}

\newif\ifequal
\makeatletter
\def\isequal#1#2{
	\ifnum\pdf@strcmp{#1}{#2}=0
		\equaltrue
	\else
		\equalfalse
	\fi
}
\makeatother

%Document
\isequal{\currfilepath}{testCurrfile.tex}
\ifequal
	The current filename is \currfilepath
\else
	Apparently the current filename is not \currfilepath
\fi
HTH,
Tom
leo simon
Posts: 17
Joined: Wed Aug 19, 2009 5:41 pm

Re: Recovery of Value by Condition

Post by leo simon »

Thank you very much indeed, Tom, this is perfect, Leo
Post Reply