Generalmacro for path to texmf-dist

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
mcswell
Posts: 9
Joined: Sun Apr 08, 2012 4:15 pm

macro for path to texmf-dist

Post by mcswell »

Is there a (xe)LaTeX macro to provide the path to the current texmf-dist directory?

I'm using the fontspec package to load some fonts for xelatex. The way our /etc/fonts/local.conf cat file is set up, fontspec finds an old version of a particular font (DejaVu Sans Mono) in /usr/share/fonts/dejavu/, rather than the newer version in our TeXLive 2016 directory.

I can tell fontspec to find the DejaVu font in the right directory using the 'Path' argument, like:

Code: Select all

\setmonofont[Path=/foo/bar/2016/texmf-dist/fonts/truetype/public/dejavu/]{DejaVuSansMono.ttf}
but there's a different path to 2016/texmf-dist on different computers. (I guess most people install TeXLive under /usr/share/, but that's not how it's done on our computer at work...)

If there were a macro that pointed to an installation's texmf-dist dir (as specified by the kpsewhich variable TEXMFDIST), then I could have a portable definition in my .tex (or .sty) file. Is there? Google may be my friend, but it hasn't told me the answer to this one...

I guess an alternative (kludge) would be to run kpsewhich and send its output to a file, and read the file. I could do that using the code here:
http://tex.stackexchange.com/questions/ ... tance-home
But xelatex refuses to allow \write18 unless you specify -shell-escape on the command line--for the very good reason that it's a security risk (if you compile someone else's malicious latex code).

And no, I can't edit the computer's /etc/fonts/local.conf file, because I'm not root.

So putting my question differently, is there a way to determine the value of TEXMFDIST from within xelatex without running \write18? Or is there another way to do what I want (find the correct DejaVu font file) from within xelatex? I don't want to rely on a command line argument to xelatex, or setting my personal .texcnf file, or anything like that--I want the solution to be self-contained in my .tex file.

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

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

macro for path to texmf-dist

Post by rais »

Hi,
well, for me, egreg's suggestion for pdflatex works for xelatex, too.
Skipping the test on LuaLaTeX, the code shortens to

Code: Select all

\documentclass{article}

\usepackage{catchfile}
\newcommand{\getenv}[2][]{%
  \CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{\endlinechar=-1}%
  \if\relax\detokenize{#1}\relax\temp\else\let#1\temp\fi}

\begin{document}
\getenv[\TEXMFDIST]{TEXMFDIST}\show\TEXMFDIST
\end{document}
which---using xelatex foo.tex---results in

Code: Select all

> \TEXMFDIST=macro:
->/usr/local/texlive/2016/texmf-dist.
on my machine with (TL default) restricted write18 enabled.

KR
Rainer
mcswell
Posts: 9
Joined: Sun Apr 08, 2012 4:15 pm

macro for path to texmf-dist

Post by mcswell »

Thank you, I confirm that your version does work!

I had tried something like that earlier, but I thought I was getting a (rather uninformative) error msg, because latex stopped immediately after the \show. But that's what it's supposed to do, I now realize :-).
Post Reply