1

I am using this command in latex to specify the font path:

\setmainfont[Color=primary, Path = fonts/source-han-serif/,BoldItalicFont=SourceHanSerifSC-Bold,BoldFont=SourceHanSerifSC-Bold,ItalicFont=SourceHanSerifSC-Bold]{SourceHanSerifSC-Regular}

now I have a issue that, I have many cls files that contains the font path, if I want to change the file path, I have to open each cls file and edit one by one. is it possible to make setmainfont to read the environment that I can specify the font path in one place? my possible operation system is Ubuntu and macOS.

Dolphin
  • 843

1 Answers1

1

Yes, you can use my code at https://tex.stackexchange.com/a/62032/4427

Here I use a variant of a previous answer to your question about HOME, just by way of example.

\documentclass{article}
\usepackage{fontspec}

\ExplSyntaxOn \NewDocumentCommand{\getenv}{om} { \sys_get_shell:nnN { kpsewhich ~ --var-value ~ #2 } { } \l_tmpa_tl \tl_trim_spaces:N \l_tmpa_tl \IfNoValueTF { #1 } { \tl_use:N \l_tmpa_tl } { \tl_set_eq:NN #1 \l_tmpa_tl } } \ExplSyntaxOff

\getenv[\HOME]{HOME}

\getenv[\TEST]{TEST}

\newfontface{\fell}{IMFePIit29C}[ Path=\HOME/provaccia/conf-1.7b/fell/, Extension=.otf, ]

\begin{document}

\texttt{TEST is \TEST}

\texttt{TEST is \getenv{TEST}}

{\fell Hello}

\end{document}

I run this on bash as

TEST=foo xelatex dolphin

and the output is

enter image description here

Of course you're responsible for correctly defining and exporting the environment variable you need on each system.

egreg
  • 1,121,712