2

In order to solve this issue, I would need to programmatically get the -output-directory when running a commands like:

$ pdflatex -shell-escape -output-directory=build test.tex

The reason is that I would need to change commands run via \write18 depending on the location of the build folder.

(I also tried to directly read ${TEXMF_OUTPUT_DIRECTORY} from the command line, but this environment variable is empty as well: EDIT after checking the source, this seems to be available starting from TexLive 2024)

tobiasBora
  • 8,684
  • 4
    adding the output-directory option to tex was such a bad idea, it adds far more problems than it solves – David Carlisle Jan 16 '24 at 00:21
  • I got once the request to support that in newpax https://github.com/u-fischer/newpax/issues/21 – Ulrike Fischer Jan 16 '24 at 00:31
  • @UlrikeFischer Actually, I'd love support for subfolders in newpax, the number of files cached when using robust-externalize is so large that no-one would like to have it in its current directory. – tobiasBora Jan 16 '24 at 00:37
  • putting generated files in a cache-subfolder is something quite different to the general --output-directory option. – Ulrike Fischer Jan 16 '24 at 09:35
  • @UlrikeFischer yeah, but it means that to includes files from this subfolder with newpax support, I'm screwed since all files must be in the current folder for newpax to work. – tobiasBora Jan 16 '24 at 11:59
  • @user202729 ahah the currfileabsdir is a very fancy trick, nice one! Thanks! – tobiasBora Feb 14 '24 at 00:35

2 Answers2

3

--output-directory is certainly more trouble than its worth but since it's there I suppose you have to support it.

Assuming the output directory is below the current directory and a unix find is available then you can do for example


\input{|find . -name \jobname.log}

\bye

which will print the path to the log file, including output-directory you could similarly \input into a definition that to get the path for further processing.

David Carlisle
  • 757,742
  • Thanks, but I have a few issues with this: first it would not work in windows out of the box, and, more importantly, if the file has been compiled before without any output directory, there might be several files with the name \jobname.log. – tobiasBora Jan 16 '24 at 00:34
  • Also, any idea why the ${TEXMF_OUTPUT_DIRECTORY} is not set? – tobiasBora Jan 16 '24 at 00:37
  • 1
    for the second issue you could first write a unique file eg using current time, then find that, why would you expect any setting in the shell environment? – David Carlisle Jan 16 '24 at 00:58
  • Hum, that could work, thanks, but seems a bit hacky. For now, I guess I will just ask the user to specify this folder manually like pdflatex -shell-escape -output-directory=build "\def\robExtOutputDirectory{build}\input{test.tex}"… For the environment, I read the code of pdflatex where I can find stuff like Furthermore, if the ‘-output-directory’ option is specified, its argument is saved in the environment variable ‘TEXMF_OUTPUT_DIRECTORY’. This is for the benefit of any subprograms that might be called via write 18, such as kpsewhich. – tobiasBora Jan 16 '24 at 01:07
  • Oh apparently, this feature was added in TeXLive 2024. – tobiasBora Jan 16 '24 at 01:07
  • 1
    @tobiasBora ooh you mean "will be" not "was" tl2024 isn't even in public test yet so that will be a while, but for future reference do you want to post (and accept) that as an answer I'll leave this answer as is for older systems. – David Carlisle Jan 16 '24 at 10:57
3

I ended up asking the user to compile with something like:

$ pdflatex -shell-escape -output-directory=build "\def\outputDirectory{build}\input{test.tex}"

(see also pre_latex in latexmk)

But starting from TeXLive 2024, a new environment variable should be defined:

${TEXMF_OUTPUT_DIRECTORY}

which should help to run commands with -shell-escape correctly.

tobiasBora
  • 8,684