Windows paths use backslash, but paths in LaTeX documents require foreslash. When copying filepaths from Windows Explorer they will contain backslash.
I know that I could use a text editor using find & replace to change backslashs into a foreslashs which would be pretty painful for every path.
So, I hoped that there might be either
- a feature in TeXStudio (Win10) to account for that
- or a TeX function which does the replacement,
e.g. like a function
\bs2fs{C:\user\test\path\subdir\file.pdf}
I have found this question with answer and so far ended up in shortening my case to the following:
\documentclass[a4paper,10pt]{article}
\usepackage{pdfpages}
\makeatletter
\newcommand{\replaceBS}[2]{{\escapechar=`/
\xdef#2{\expandafter\zap@space\detokenize\expandafter{#1} \@empty}}}
\makeatother
\begin{document}
\replaceBS{C:\user1\test\path\sub dir\sub dir2\file_name with Umlauts äöü.pdf}{\TeXFilename}
\includepdf[pages=-]{\TeXFilename}
\replaceBS{C:\user2\test\path\sub dir\sub dir2\file_name with Accents àèòù.pdf}{\TeXFilename}
\includepdf[pages={1,3,4,2}]{\TeXFilename}
\replaceBS{C:\user3\test\path\sub dir\sub dir3\file_name with Umlauts.pdf}}{\TeXFilename}
\includepdf[pages={4,3,2,1}]{\TeXFilename}
\replaceBS{C:\user4\test\path\sub dir\sub dir4\file_name with Umlauts.pdf}{\TeXFilename}
\includepdf[pages={1,4,3,2}]{\TeXFilename}
\end{document}
This basically works but doesn't seem to handle spaces in the path. Can't this be shortened to a simple "function" like \bs2fs{<path>}
which would make the document more readable? Actually, a function which additionally handles spaces, umlauts and accents as well?
\includepdf[pages=-] {\bs2fs{C:\user1\test\path\sub dir\sub dir2\file_name with Umlauts äöü.pdf}}
\includepdf[pages={1,3,4,2}]{\bs2fs{C:\user2\test\path\sub dir\sub dir2\file_name with Accents àèòù.pdf}}
\includepdf[pages={4,3,2,1}]{\bs2fs{C:\user3\test\path\sub dir\sub dir3\file_name with Umlauts.pdf}}
\includepdf[pages={1,4,3,2}]{\bs2fs{C:\user4\test\path\sub dir\sub dir4\file_name with Umlauts.pdf}}
\user1
and\user 1
. that having said, it's not impossible if you're willing to wrap every\includepdf
statement with something like\beginreplace ... \endreplace
and ensure that it does not appear in the argument of anything else.