1

I am seeking to include in a latex run a range of files off different paths; I am working in MiKTeX 2.9 under Windows 10. I am unable to get \string~ to point to %USERPROFILE%.

A MWE to illustrate is:

\documentclass{article}
\usepackage{graphicx}

% I put mypic.png in my Home Folder; I'm running Windows 10, MiKTeX 2.9, % executing pdflatex both in command line and in TeXWorks % \newcommand\HomeFolder{\string~} %1 %\newcommand\HomeFolder{$HOME} %2 %\newcommand\HomeFolder{C:/Users/MyLoginName} %3

\begin{document} \includegraphics{\HomeFolder/mypic} \end{document}

uncommenting in turn the \newcommand labelled 1, 2, and 3. The results are, respectively:

! LaTeX Error: File `~/mypic not found.
! LaTeX Error: File `$HOME/mypic not found.

and success on 3. (That one puts in my %USERPROFILE% explicitly.) Does tilde point somewhere other than %USERPROFILE% in MiKTeX? If so, is there a way to reset ~ to %USERPROFILE? Or is the issue more general?

Put differently, is the "\includegraphics{\string~/foo} should work" in David Carlisle's answer in Reference file relative to the home directory known to apply (or not) to MiKTeX 2.9? This ought to be pretty basic but I have not been able to see direct statement on it one way or the other.

(This MWE above illustrates the point I'm trying to make about accessing paths off my home folder. I realise that if my home directory is in my TEXINPUTS path, then I don't need to qualify the inclusion of mypic.png. However, the use cases I am working with are about paths more generally, of which the problem above is just a special case.)

The report https://sourceforge.net/p/miktex/bugs/2535/ discusses how it is pdftex.exe, not MiKTeX, that is the problem for handling tilde. Here, however, the problem applies to pdflatex as well, whereas in 2535's illustration pdflatex works the tilde fine, even if there pdftex does not.

Danny Quah
  • 65
  • 8

1 Answers1

3

In TeXlive and windows 10 \string~ works and points to %USERPROFILE%. Using $USERPROFILE works too:

\includegraphics{\string~/Documents/test.pdf}
\includegraphics{$USERPROFILE/Documents/test.pdf}

This is a feature of the kpathsea library used by TeXlive to search files.

MiKTeX doesn't use kpathsea and neither of both works. I'm not aware of another way to get directly variable expansion in a document in a similar way to TeXlive when using MiKTeX (something with lua or pipes are perhaps possible).

The bug you mentioned is not related, this was about actual tildes in file names. But I checked environments variables on the command line.

If the file exists something like this works fine in both texsystems:

pdflatex %USERPROFILE%/path/to/test

If the file doesn't exist the behaviour of MiKTeX and TeXLive is different. MIKTeX expands the variable but then complains on the backslashes:

C:\Users\XXX\Documents>pdflatex %USERPROFILE%/tests/test.utf8
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.11)
entering extended mode
! Undefined control sequence.
<*> C:\Users
            \XXX/tests/test.utf8

TeXLive on the other side complains about a missing file:

! I can't find file `C:/Users/XXX/tests/test-utf8'.
<*> C:/Users/XXX/tests/test-utf8

Side remark: I would never call pdflatex like this, but always switch first into the folder of the tex files and then use pdflatex test, so imho this is only an akademic difference.

You could make a feature request at https://github.com/MiKTeX/miktex/issues.

Ulrike Fischer
  • 327,261