0

There are numerous questions on this site (and elsewhere on the web) how to define $TEXINPUTS and other strategies for including non-standard locations to be searched by TeX. See, for instance the discussions here, here (for texmaker), here (for Texstudio), here, here (for MikTeX), here (for TeXShop), here (macOS), or here. From all those discussions (a lot of helpful explanations buried in comments) I gather that there are many different ways of defining the variable and that it depends on the operating system, TeX distribution, and program what will work and what won't.

I'm on macOS and use TeXShop. I have a location at ~/custompath/input/ with a bunch of subfolders for graphics, figures etc., which I would like TeX to access without having to specify explicit paths (which I know I can do via \def\input@path{...}).

Temporarily, I've learned I can define the variable via command line with

export TEXINPUTS=.:~/custompath/input//:

A more permanent solution should be to add TEXINPUTS = .:~/custompath/input//: either to

~/.bashrc

or

 /usr/local/texlive/YYYY/texmf.cnf

The first method (via export TEXINPUTS=.:~/custompath/input//:) does work as expected when I run pdflatex from the same command line window. I understand that since it's temporary I can't expect this to work in TeXShop.

But I fail at getting any of the other methods to work. Placing the magic line in ~/.bashrc has no effect whatsoever.

When I add it to texmf.cnf, then I can run from the command line

kpsexpand '$TEXINPUTS'

and that does return .:~/custompath/input//:
However, compiling (again from the command line pdflatex ~/custompath/testing.tex) gives me:

`! LaTeX Error: File `testinput.tex' not found.`

And, needless to say, nothing works from TeXShop.

Is there a bulletproof way to define an additional location to be searched by TeX that will always work, no matter if I'm invoking LaTeX from the command line, using TeXShop, or another front end? My hunch is the answer is no, but perhaps someone can explain how to get it to work for different systems/installations/front ends. (I'm particularly interested in TeXShop, of course, but it seems people on other platforms frequently run into similar issues, so maybe it's worth to have an authoritative answer for all scenarios ...).

MWE for what it's worth, with testinput.tex at ~/custompath/input/figures/project1/ :)

\documentclass{article}
\begin{document} test document \par
\input{testinput.tex}
%\input{~/custompath/input/figures/project1/testinput.tex} % 
\end{document}
jan
  • 2,236
  • 1
    I would expect ~/texmf is already in your default path so the simplest thing is to use that name rather than ~tex. Check kpsexpand '$TEXINPUTS' – David Carlisle Dec 15 '23 at 23:36
  • don't use the environment variable TEXINPUTS as that masks the setting in texmf.cnf and your editor, if launched from the dektop may not share the same environment – David Carlisle Dec 15 '23 at 23:38
  • @DavidCarlisle The point of my question was to find a way to input a random custom folder that is not already in the default path. I've edited the question to make that clearer, calling the folder in my homefolder now "custompath" as opposed to "tex" to not create any confusion. In regards to your second comment, if not $TEXINPUTS, then how can I achieve what I want (making a custom folder plus subfolders visible to tex)? Is there an alternative method? – jan Dec 16 '23 at 02:47
  • Why don't you want to use ~/texmf? It's possible to add an addition tree either permanently (as I do for /usr/share/...) or temporarily as people sometimes do for testing. But there are particular reasons for those structures and it isn't clear whether you plan to structure this as another tree anyway. – cfr Dec 16 '23 at 02:59
  • @cfr Well, in my particular use case I have all my writing projects in one place, logically organized in an old-school folder structure with subfolders for different projects under the system Documents folder (the actual path is quite long, simplified in the example above). All research material for these projects is organized there as well, so I wouldn't want the entire directory to be available to TeX – only one folder (called input) with subfolders with files that are shared between projects (figures, examples, graphs, tables, pictures, etc.). – jan Dec 16 '23 at 03:25
  • @jan I use a mixture of 2 approaches for that kind of case. (1) In some cases, I put the resources under $TEXMFHOME. (2) In other cases, I keep them outside, especially if they are relevant to only a certain category of documents (e.g. they're chunks or examples I use in teaching materials, but not writing or research). Especially for teaching, I add some of these directories in custom classes or packages and only quite specific ones in each project or document config. All custom classes and packages are under $TEXHOME. These also define commands which utilise other, task-specific places. – cfr Dec 16 '23 at 05:21
  • macOS GUI programs do not read .bashrc or similar: this is a design decision by Apple - as such you cannot use exactly the same methods for all OSs. – Joseph Wright Dec 16 '23 at 07:51
  • 1
    you can symlink your tex folders under texmf – David Carlisle Dec 16 '23 at 08:16
  • @DavidCarlisle sure, that's the workaround I've been using – but I was hoping there was a better/official solution – jan Dec 16 '23 at 16:44
  • set the variables in texmf.cnf (not the environment) is the other way, – David Carlisle Dec 16 '23 at 16:47
  • @JosephWright ok, understood ... but even when I add TEXINPUTS=.:~/custompath/input//: to texmf.cnf, while kpsexpand '$TEXINPUTS' returns the custom location, when compiling I still get the file not found error (whether in a GUI program or from the command line). – jan Dec 16 '23 at 16:48
  • @DavidCarlisle Could you explain how? I thought that was I was doing (which didn't work) ... – jan Dec 16 '23 at 16:50
  • make sure it's not set in the shell. TEXINPUTS=.:~/custompath/input//: to texmf.cnf sounds wrong, that will mask the original setting, probably something like TEXINPUTS.tex = $TEXMFDOTDIR;$TEXMF/tex/{plain,generic,latex,}// you want to set TEXMFHOME as described in the comments in texmf.cnf % Per-user texmf tree(s) -- organized per the TDS, as usual. To define % more than one per-user tree, set this to a list of directories in % braces, as described above. (This used to be HOMETEXMF.) ~ expands % to %USERPROFILE% on Windows, $HOME otherwise. TEXMFHOME = ~/texmf – David Carlisle Dec 16 '23 at 16:59
  • @DavidCarlisle I'm making some progress figuring this out. Adding TEXMFHOME = ~/custompath/input// to /usr/local/texlive/2023/texmf.cnf does work but only if I move the file in question to a subfolder of ~/custompath/input/tex/latex/ – "organized per the TDS, as usual" (I get it now). But what I was trying to accomplish is to directly input the folder without yet again having to bury the files two levels down (as then my current method with a symlink is still easier). From what I had been reading, it seemed that TEXINPUTS was the way to go but I couldn't get it to work. – jan Dec 19 '23 at 15:33
  • you could set TEXINPUTS directly to whatever directory you want but make sure to add it to a copy of the default setting or you will end up with only allowing your new directory and removing the main texlive tree from the input path. – David Carlisle Dec 19 '23 at 15:36
  • @DavidCarlisle Sorry, but can you explain what you mean by "add it to a copy of the default setting"? – jan Dec 19 '23 at 15:41
  • looking in my texmf.cnf I see TEXINPUTS.pdflatex = $TEXMFDOTDIR;$TEXMF/tex/{latex,generic,}// so you want TEXINPUTS.pdflatex = $TEXMFDOTDIR;$TEXMF/tex/{latex,generic,}//,/some.path.to/somewhere if you just set it to your path pdflatex won't look in the standard places so \documentclass{article} wouldn't find article.cls – David Carlisle Dec 19 '23 at 15:44
  • @DavidCarlisle I've added TEXINPUTS.pdflatex = $TEXMFDOTDIR;$TEXMF/tex/{latex,generic,}//,/~/custompath/input to /usr/local/texlive/2023/texmf.cnf – but still getting file not found :( – jan Dec 19 '23 at 15:56
  • (as specified above, file is at ~/custompath/input/figures/project1/testinput.tex) – jan Dec 19 '23 at 15:57
  • semicolon not comma and not /~ just ~ or use the full path – David Carlisle Dec 19 '23 at 16:06
  • @DavidCarlisle I have no idea what I'm doing wrong, I still get "file not found" – jan Dec 19 '23 at 16:12
  • 1
    sorry I have no mac. I'm out. Stick to symlinks? – David Carlisle Dec 19 '23 at 16:34

0 Answers0