A file may be accessed by different paths. For example,
- subpath/myfile.tex
- ./subpath/myfile.tex
- ../current path/subpath/myfile.tex,
- /d/.../current path/subpath/myfile.tex
They refer to the same file myfile.tex under current path.
Given these different paths, how can I make a macro to check if they are the the same file?
Example:
\documentclass{article}
\newcommand\ifsamefile[4]{
% if file #1 is in file-list #2(which is a comma list)
% then do #3
% else do #4
}
\begin{document}
\ifsamefile{myfile}{./myfile.tex,file2.tex}{true}{false} %should be true
\ifsamefile{myfile}{../current path/myfile.tex,file2.tex}{true}{false} %should be true
\issamefile{subpath/file1.tex}{./subpath/file1.tex,subpath/file2.tex}{true}{false} %should be true
\issamefile{subpath/file1.tex}{/d/mypath/current path/subpath/file1.tex,./subpath/file1.tex}{true}{false} %should be true
\end{document}
ln filea fileband thenfileaandfilebare the same file at all effects. Add in directories symbolically linked and you have a nice mess ;-). – Rmano Jul 20 '22 at 07:08\immediate\openout1 <path1> \immediate\openout2 <path2>for two paths to the same file, my TeX implementation produces a "Runtime error 5" and exits. Perhaps other implementations fail gracefully so that\ifeof2can be evaluated? That would also catchln filea filebcases. – Heiko Theißen Jul 20 '22 at 07:28Use shell escape and some bash scripting (or Lua scripting). I think TeX doesn't really have a built-in for this.I thought it was about symlinked files, but I see you only consider the same path instead of same file. So yes it's duplicate of your other question. You need an expandable input though. (by the way if you are serious about TeX programming I recommend reading the TeXbook/TeX by topic. Will save you some trouble (and questions) later on.) – user202729 Jul 20 '22 at 08:17