How can LaTeX always find image files that I use in my letterhead?
May 3, 2020 9:49 PM   Subscribe

I have a LaTeX template for producing my university's letterhead. It requires that I include a couple of logo .pdf images. Where can I put these images so that wherever I'm saving a file, the file will be able to compile and find the images?

I'm using TeXShop 4.44, MacTeX (I don't know what version, nor do I know how to find out), and macOS Catalina. I've tried putting the images in ~/Library/texmf/tex/latex, but that doesn't seem to work. (But I didn't do anything except put the files there; I don't know if I was supposed to also do something in TeXShop.)

I tried putting the images in the Stationery folder, and that unsurprisingly did not work.
posted by leahwrenn to Computers & Internet (7 answers total) 3 users marked this as a favorite
 
I think you probably need the images to be in the same place as your .tex file, but also check in the style file or template to see where it specifies the images and see if a particular folder is given (eg "images/file01.png" would mean you need to create an images folder inside the same folder where your tex file is and put the file 01.png in there.)
posted by lollusc at 10:21 PM on May 3, 2020


You can use the import package in each of your documents' preambles, to specify the files you want to use:
\import{~/Documents/uni_logos/}{logo.pdf}
Which would then be recognised by the usual \include, \input methods.
posted by Fiasco da Gama at 11:55 PM on May 3, 2020 [1 favorite]


You can use \graphicspath{{/path/to/some/folder}} with the graphicx package to set a folder that will be searched for any graphics not found in the local folder. So you could create your own centralized graphics folder or use an existing one, and then put the \graphicspath{{}} command with the absolute path to your folder into the preamble of all your .tex files. (There are two sets of braces, because you can set multiple paths: \graphicspath{{path1}{path2}} etc.)
posted by egregious theorem at 12:05 AM on May 4, 2020 [2 favorites]


Hard mode. Run your program under dtruss. macos - How to trace system calls of a program in Mac OS X - Stack Overflow.

Under Linux, you'd use strace but the idea is the same. These programs will run your program and log all of the system calls that your program uses. So you go through that log and look for where it's trying to open your PDF that it can't find. You can find the places that it actually looks for the file, then you know where to put the file. If it does search for that file in several locations you'll see a bunch of attempts to 'open' '/somepath/my.pdf'.

This is the totally dig into the brains of the program and see how it's actually trying to do something. Sometimes it's faster than reading the man pages. :)
posted by zengargoyle at 3:51 AM on May 4, 2020


I'd try putting it in the same place as the .cls or .sty file. You might need to do something to update a file database afterwards, however one does that in texshop.
posted by GCU Sweet and Full of Grace at 4:27 AM on May 4, 2020


I have a "letters of recommendation" folder for which I have to include a logo, letterhead, signature, etc. The way I do it is to use the "parent directory" construction. I have a folder "Recommendations". The PDF files for the letterhead live in this top-level directory. LaTeX source for the ndividual letters for each student (say, "Joyce Brown") are in a subdirectory labeled by the students' names. In each source file, I include the graphics with the following command:
\includegraphics{../logo.pdf}
The two dots mean "one directory up" in Unixese. It works like a charm, and doesn't require me to create umpteen copies of the logo PDFs.

Also, to check your distribution: when you run LaTeX on a source file, you should be able to tell from the directory paths that show up in the console.
posted by Johnny Assay at 4:44 AM on May 4, 2020 [2 favorites]


It will work if it’s in the same folder, or you can include it from elsewhere.

But the LaTeX way to easily do this would be to put the images in your local texmf tree. What you probably didn’t do is build the texmf tree using texhash. Just do that (possibly googling better instructions) and you should be good.

Some advice along those lines as well as a path macro I haven’t used mentioned in this thread here.
posted by SaltySalticid at 5:13 AM on May 4, 2020 [2 favorites]


« Older Where is this Temple of Apollo located?   |   How to talk about parameters in a casual... Newer »
This thread is closed to new comments.