# Setting TEXMFHOME variable when using Miktex portable

Apparently Miktex sometimes doesn't properly set the TEXMFHOME variable, or rather leaves it empty, even though you manually add folders to the "root" list and refresh the file name database. So how do I set the TEXMFHOME variable? Another way of phrasing the question: What is the Miktex version of tlmgr conf texmf TEXMFHOME ~/path/to/texmf ?

-
It seems, there is no way for changing the variable. What do you want to do? Maybe, we can help you in another way. –  Speravir Mar 1 '12 at 22:28
The problem is that because texmfhome is always empty, Miktex won't use any of the files in my texmf folder, no matter how often I add it to the root directory and refresh the database. I simply want to be able to use my local texmf folder and the files contained in it. –  jjbornheim Mar 2 '12 at 8:37

First a remark:
I do not use MikTeX portable myself, and honestly I don’t understand it entirely. So let me give some hints from what I’ve found. Maybe some other can give additional information.

MiKTeX apparently does not take use of the kpse mechanism. The recommended method in MikTeX for adding a local TeXMF tree is to use the MiKTeX Options dialogue:

1. Start MiKTeX portable by execution of the included miktex-portable.cmd.
2. Do a right mouse click on the traybar icon, that appeared and choose “MiKTeX Options”.
3. Choose there the tab “Roots” and add your local TEXMF tree. It will be saved as relative path in the <miktex-portable>\miktex\config\miktexstartup.ini. Your local TEXMF tree must not be a subfolder of <miktex-portable>.
4. What I wanted to do now doesn’t seem to work, I consider it a bug in MiKTeX 2.9: After activation of “Show MiKTeX-maintained root directories” one should be able to change the order of the folders, but I couldn’t manage this.
5. After clicking on “OK” all will be saved in ini as written above.

According to <miktex-portable>\doc\miktex\miktex.pdf, section 4.6, (or see <miktex-portable>\doc\miktex\localadditions.html, as web link : http://docs.miktex.org/manual/localadditions.html) there are 2 other ways:

• Use the command-line option --include-directory=dir, e.g. latex --include-directory=C:\path\to\my\style\files thesis.tex. I don’t know, whether this works with a full local TEXMF tree, but I fear it does not.
• Set environment variables, which are useful in scripts alias batch files. The given example is
set TEXINPUTS=C:\path\to\my\style\files

latex thesis.tex

Instead of absolute paths I would favour relative ones together with the use of command line parameters, e.g. if you save a batch script latex.cmd directly in lets say X:\miktex-portable and have your local TEXMF tree in X:\localtexmf

@echo off
setlocal

set LOCALDRIVE=%~d0
set LOCALPATH=%~dp0
:: %~d0 enhances to X: here, %~dp0 to X:\miktex-portable\

set PATH=%LOCALPATH%miktex\bin;%PATH%
set TEXINPUTS=%LOCALDRIVE%\localtexmf
:: I fear, this does not work in the wanted manner
:: There are some other possible environment variables

latex %*
:: %* pipes all command line options, given to to batch file, to the call of latex.exe

Then you could do latex.cmd <command line options> file_to_compile.tex.

On the other hand you could consider the use of the portable texlive version.

-
Thanks a lot. I had already done the standard procedure and even though in my case, I could rearrange the order of folders (step 4), and the path was correctly written to the ini file (I just looked at it), Miktex still seems to ignore the contents of this folder. I will try the batch script tomorrow at work, as I don't have a working Windows installation at home. I might also take a look at texlive portable instead. There is really no reason why I use Miktex portable rather than texlive portable other than that I found it first and I use texlive at home. –  jjbornheim Mar 4 '12 at 12:37
@jjbornheim: Thanks for your response, especially about step 4. If the recommended method does not work correctly (I didn’t try this), consider to file it as a bug at the MiKTeX development site. Concerning the batch file: In dependency of what you want to do it may be necessary to add some more environment variables. See for that in the mentioned PDF or linked HTML file. –  Speravir Mar 4 '12 at 18:21
I marked the question as answered. Making sure the path is in the ini file is essentially what I wanted to know and the fact that Miktex does not properly use the path in the ini file is not really your fault. For my immediate purposes, --include-directory worked because I needed a few very specific files from my texmf tree. –  jjbornheim Mar 6 '12 at 13:35