1

I want to have a directory called "Templates" where I would like to have .tex files and image files for inclusion. An example template would setup a letter format with watermark, fancy header, language settings, font selection etc. I want to have my templates at one place, and have all other documents at another location. For example:

Documents
   |
   |-  Templates
   |     |
   |     |-- letter_header.tex
   |     |-- company_watermark.png
   |
   |- Contracts
   |     |
   |     |-- Company 01
   |     |     |
   |     |     |-- contract01.tex
   |     |     |-- contract02.tex
   |     |     |-- contract03.tex

Here is my problem. From contract01.tex I would like to do something like this:

\include{../../Templates/letter_header.txt}

However, this won't work because LateX cannot write aux files in that directory. Under Microsoft Windows, there is no symbolic link that could be used. I understand that it is a security risk to allow latex to write into any directory ( (How) can I include the file somedir/file.tex in the file somedir/subdir/anotherfile.tex ). So what is the safe way? Can I specify that under "Documents" it should be able to write to any directory?

Most important question: there must be thousands using LateX with their own templates, and they probably want to separate template code from actual content. Are all of them forced to use clumsy / unsafe solutions?

UPDATE:

Uploaded an example here: https://www.dropbox.com/s/15dxnu48wdqp897/SyncedFolder.zip

What I want is to be able to use my businessletter class from test01.tex, test02.tex, test03.text or from any folder under SyncedFolder/Documents. The watermark.jpg file belongs to the businessletter class, and so it should be loaded from the class file.

results of setting TEXINPUT:

enter image description here

nagylzs
  • 1,225
  • why do you want to use \include rather than \input or better just use \documentclass{myletter} that way you only ever need to write aux files to teh current directory – David Carlisle May 07 '14 at 12:04
  • I would use a custom documentclass rather than inputting header code explicitly but if you want to do the latter just use \input{letter_header} and arrange that Documents/Templates is in your TEXINPUTS path, you should not need to put tthe path in the document, just as you don't use \input{/texlive/texmf-dist/tex/latex/base/article.cls} – David Carlisle May 07 '14 at 12:07
  • \input does not work because I have images included in letter_header. They are also located in the templates directory. Unfortunately, \input does not change the current dir so it would be impossible to use relative paths to access the images from letter_header. – nagylzs May 07 '14 at 18:01
  • \input and \include work the same way as far as image inclusion works, and anyway images are searched on teh tex path so if they are in that directory in TEXINPUTS you would just need \includegraphics{localname} – David Carlisle May 07 '14 at 18:03
  • Okay, so in letter_header.tex I have this:

    \fancyhead[RE,LO]{\includegraphics[width=1cm]{sm_stamp.png}}

    If I use \input instead of \include then I get this:

    LaTeX Warning: File `sm_stamp.png' not found on input line 48. ! Unable to load picture or PDF file 'sm_stamp.png'.

    The png file and the letter_header.tex file are in the same directory. So I guess \include changes to the directory of letter_header.tex and \input doesn't. As a result, relative image paths cannot be used from letter_header.tex.

    – nagylzs May 07 '14 at 19:02
  • I would use a document class. But is it possible to add actual content from a document class? I thought it should only be used for creating styles, not content. – nagylzs May 07 '14 at 19:03
  • No. \include just does some stuff that you don't want such as doing a \clearpage and saving the values of all counters in the aux file, and then does \input. – David Carlisle May 07 '14 at 19:04
  • Its hard to say as you have not provided any example (all questions should include an example document) but typically any fixed texts are attached to some command such as \begin{document} or \maketitle or some such, the document class can arrange that text appears when any command is used. – David Carlisle May 07 '14 at 19:06
  • I have accepted the answer that I got. But using a document class does not seem to be a good solution, because these files should be synchronized with dropbox or google drive across many computers. Document class needs to go into TXMFHOME which will never by sync-ed. – nagylzs May 15 '14 at 18:25
  • No. you can put the document class anywhere you like, in particular in the same directory as your document. – David Carlisle May 15 '14 at 18:31
  • I just added an MWE as a zip file link. Under "adding content from a document class" I meant something like setting the watermark image or change the font with a physical TTF file etc. Please see the example - how can I use my businessletter class from any folder? Right now the businessletter cannot load the watermark file because it does not know where it is. – nagylzs May 16 '14 at 14:56
  • 1
    the MWE should be small enough to paste inline (unless you plan to maintain that dropbox link foreverand not break the archives of this site) tex looks in the places specified in TEXINPUTS which can be set as an environment variable, or in a texmf.cnf config file, or depending on your environment system, on the command line, I can go TEXINPUTS=.//: pdflatex myfile and then tex will find any tex or image files at any depth of any subdirectory of the current directory. Replace .// by any suitable place on your machine where you want it to look – David Carlisle May 16 '14 at 15:00
  • Or just edit TEXMFHOME to be your dropbox folder – David Carlisle May 16 '14 at 15:02
  • After setting TEXINPUTS to "TEXINPUTS=.//" I get "I can't find the file 'text01.tex'" error. Besides, some persons suggested here that "you should not set TEXINPUTS. You'll get problems when using ConTeXt or LuaTeX beside pdflatex" see http://tex.stackexchange.com/questions/93712/definition-of-the-texinputs-variable but maybe he was wrong – nagylzs May 16 '14 at 15:11
  • That is why I had a trailing : to search the standard places as well as .// – David Carlisle May 16 '14 at 15:15
  • See the image at the end of the question. – nagylzs May 16 '14 at 16:13
  • 1
    That set TEX T INPUTS so does nothing, and presumably you had earlier set TEXINPUTS to the wrong thing – David Carlisle May 16 '14 at 16:20
  • I'm sorry I'm acting like a child. Under windows, how do I set it to contain the current dir, and "c:\temp\any_folder"? Using TEXINPUTS=".//:c:\temp\any_folder" obviously does not work because : is used for separation. :-s – nagylzs May 16 '14 at 17:47

1 Answers1

0

Assuming you're on TeX Live for Windows, here's what works for me:

  1. Find out where your TEXMFHOME folder is located:

    C:\Users\renfro>c:\texlive\2013\bin\win32\tlmgr conf | find /i "TEXMFHOME"
    TEXMFHOME=C:/Users/renfro/texmf
    
  2. Make folders for your class content, complying with the TeX Directory Structure (official word from A Directory Structure for TeX Files, abridged version at the LaTeX Wikibook section Installing Extra Packages).

    C:\Users\renfro>mkdir texmf\tex\latex\base
    
  3. Copy your .cls file to the folder you just created, and use it in documents created elsewhere.

The only difference with other operating systems or other TeX distributions would be the particular paths to tlmgr, kpsexpand, etc., and to your own home directory.

Mike Renfro
  • 20,550
  • Thanks. Well this does not work nicely with dropbox or google drive. My goal was to use LaTex for creating letters, reports and contracts for my company. The style should be defined for the company. I wanted to use the same templates from my computers, and synchronize them with Google Drive. Unfortunately, it seems I cannot use Google Drive folder for making a document class. :-( And it also seems there is no way to give script-relative paths. I'm doomed. – nagylzs May 15 '14 at 17:52
  • I might write a script to recursively copy from Google Drive or Dropbox into the texmf tree, then. Using robocopy for Windows, rsync for Unix-like systems, etc. Either that, or create all documents of a particular class in one particular folder, and put the .cls in that folder as well. – Mike Renfro May 15 '14 at 20:21
  • Can't you change the location of your DropBox directory on Windows? (I've only used it on Linux so maybe the answer is 'No'.) – cfr May 17 '14 at 02:16
  • Here is the solution. For Windows, you can set TEXINPUTS to

    TEXINPUTS=.\;c:\Temp\SyncedFolder\Templates\;c:\texlive\2013\texmf-dist\tex\

    There "templates" is my templates dir and "texmf-dist\tex" is my LiveTex distribution dir.

    Here are some questions:

    Where is the value ot TEXINPUTS documented? I have spent the last two hours figuring out the syntax and the meaning, but I could find abolutely nothing on it. Why is that? It took me 30 minutes to come up with a TEXINPUTS value that actually works!

    – nagylzs May 17 '14 at 07:16
  • Also tried on Linux. Under Linux this works: export TEXINPUTS=.//:~/Dropbox/Documents/Templates: but under Windows, the trailing colon cannot be used, and the only way I could find is to use c:\texlive\2013\texmf-dist\tex\ – nagylzs May 17 '14 at 10:26