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:
- Start MiKTeX portable by execution of the included
miktex-portable.cmd
.
- Do a right mouse click on the traybar icon, that appeared and choose “MiKTeX Options”.
- 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>
.
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.
- 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.
Why change it at all? I think what you're missing is that you should make your personal texmf
-tree mimic that of the installed version. This is easily remedied.
In a terminal:
mkdir -p ~/texmf/{doc,tex}/{context,eplain,generic,latex,lualatex,plain,xelatex,xetex} # for example
mkdir -p ~/texmf/bibtex/bib # put your bib file in here
(You should / will need to make the appropriate sub-directories for bibtex
and doc
if you want to put things in there.)
Now you can test whether things are found:
touch ~/texmf/tex/latex/myfakefile.sty
kpsewhere myfakefile.sty
The last command should return:
/home/<user>/texmf/tex/latex/myfakefile.sty
Note also that the command
kpsewhich --var-value TEXMF
should return a list of places that will be searched in the order (I believe) they are searched. Your personal tree is probably listed first, which means that in a race between, e.g., the 'system' myfakefile.sty
and your 'personal' myfakefile.sty
, the personal one will win.
Finally, I should point out that your attempts at modifying texmf.cnf
may have made this answer not work (I'm not sure what you did). I would revert your changes to the default set-up as it will be easier to maintain.
Best Answer
It's not clear from the question whether you have admin access to the master
texmf.cnf
file. If you do, then this is easier than if you do not!Admin access available
In the case where for example you have a single-user machine and so write access to
texmf.cnf
in the installation directory, this is doable with no variable setting. You can find where this is usingkpsewhich texmf.cnf
: I seeYou can then edit this file (with
sudo
if needed) and alter theTEXMFHOME
line to point to where you want.Admin access not available
The more common case, I think, if wanting to set things here is when you do not have admin access which is exactly why you want to set on a per user basis. Here, it seems you have to set at least one variable. There are two approaches.
The first is to set
TEXMFHOME
directly. This is clearly pretty easy, and is the recommended method unless you need to do more complex things.The second approach is to set your system up to use a per user
texmf.cnf
file. This can go in a location of your choosing, but you will need to set theTEXMFCNF
variable with something likewhere the
:
is important as it makes this an additive change. You can then create atexmf.cnf
file in this new location, and add whatever settings you want there (TEXMFHOME
is just one possible). There is more detail on this in http://people.debian.org/~preining/TeX/TeX-on-Debian/ch2.html#s-sec-user-config-files.