111

In TeX Live there are TEXMFLOCAL for admin and TEXMFHOME for user pre-defined, but in MiKTeX there’s by default no local texmf tree installed, though it is useful, cf. Purpose of local texmf trees. Therefore my question:

How do I create a local texmf tree in MiKTeX?

1 Answer 1

124

Actually you can create more than one local TeXMF folder! There’s already a description on MiKTeX’ online documentation, see Integrating Local Additions, at time of writing for recent MiKTeX 2.9 (but the included images are from an older version, seemingly MiKTeX 2.5, and slightly different, cf. also http://docs.miktex.org/2.5/manual/localadditions.html ). The denomination there is “User-Managed TEXMF Directory” (see also additional note at the very end of this answer).

Anyway, here an alternative description:

  • Create a folder somewhere on your computer – with an important exception. It must not be a subfolder of your MiKTeX installation (it worked this way in older MiKTeX versions, but was changed for security reasons). Avoid as far as possible spaces in the path, it is a potential risk for malfunction. For use with MiKTeX portable the folder must be, of course, on the same drive as the MiKTeX installation, it will be saved as relative path. Here I will use c:\localtexmf.

    This folder must be TDS compliant (see thereto A Directory Structure for TeX Files); MiKTeX will complain, if not. What you need, depends on what you want to install into this directory, at least a tex\latex subtree should be sufficient. You will go safe, if you mimic the structure of the (itself TDS compliant) MiKTEX tree, but binaries can directly go into a subfolder c:\localtexmf\bin.

  • Now, using the GUI:

    1. In the Start Menu go to the MiKTeX entry and open the settings – if you act as admin respectively “Settings (Admin)”, of course. The “MiKTeX Options” window will open.

    2. Go to the “Roots” tab. Click on “Add” and choose c:\localtexmf\. If there are more than one local directory, one can choose the search order with the “Up” and “Down” buttons.

    3. Now the almost most important part: Go to the “General” tab and click there on “Refresh FNDB” (FNDB = File Name Data Base). In some cases, especially if new fonts are installed, one has to press also the “Update Formats” button.

    If you’d forget this step, all earlier steps would be done to no purpose.

  • Otherwise, using the command line (as admin always add the switch --admin):

    Execute initexmf --register-root=c:\localtexmf, followed by initexmf --update-fndb (shorter: initexmf -u).

    (In every step you can add the switch --verbose to get more information about, what happens.)

    Remark: For compatibility reasons there’s also the older switch --user-roots=<local-texmf-dir>, what according to initexmf --help registers user root directories, I assume also in administrative mode, but in http://docs.miktex.org/manual/initexmf.html it is not mentioned any more, so I must guess.

  • In the case, a bin subfolder for binaries was created, it should be registered in the environment variable %PATH% before the binaries subtree of MiKTeX own installation, see e.g. How To Manage Environment Variables in Windows XP or a third-party tool like Env-Man or RapidEE. Then you need a system restart to take effect. An issue, that cannot be solved: A system wide environment variable, set by an admin, is always read before a user specific one. Then as a simple user you can only write and use batch files with an own %PATH% included.

All user created local texmf trees can be disabled by temporary removing from the MiKTeX roots (cf. additional note at the end).

See also How can I manually install a package on MiKTeX (Windows).

For the sake of completeness, here’s a description, how to remove a local TeXMF tree from MiKTeX, with c:\localtexmf\ as example:

  • GUI:
    Go again to the “Roots” tab in the settings (“MiKTeX Options” dialogue), select the directory c:\localtexmf\, and click on “Remove” on the lower side of the window. After that you must again refresh the FNDB and perhaps update the format files.

  • Command line (also here: as admin add the switch --admin):
    Execute initexmf --unregister-root=c:\localtexmf, followed by initexmf --update-fndb. If you have uninstalled a font, additionally execute initexmf --mkmaps. The --verbose switch can be added, as well.

  • If you do not need the bin subfolder anymore, the environment variable %PATH% must be cleaned up.

  • Then the folder tree c:\localtexmf\ could safely be deleted.

Additional Note

A hint first: In Command Prompt you can type echo %Variable% with %Variable% e.g. %Userprofile%. So you can see to which value the variables expand on your system.

Precisely the phrase “in MiKTeX there’s by default no local texmf tree installed”  in the question is not true. MiKTeX adds itself several trees under %UserProfile% and in admin mode also to %AllUsersProfile% (in the following the MiKTeX denomination comes first):

  • “UserConfig”: %AppData%\MiKTeX\<version>\
  • “UserData”: %LocalAppData%\MiKTeX\<version>\ (since Windows Vista) or %UserProfile%\<Local Settings>\<Application Data>\MiKTeX\<version>\ (until Windows XP, the strings <Local Settings> and <Application Data> are language dependent)
  • only in admin mode used “CommonConfig” and “CommonData”: %AllUsersProfile%\MiKTeX\<version>\ (since Windows Vista) or %AllUsersProfile%\<Application Data>\MiKTeX\<version>\ (until Windows XP, the string <Application Data> is language dependent)

The actual paths you can see with the GUI in the “MiKTeX Options” window under the “Roots” tab or with the command line interface by executing initexmf --report.

Disadvantages of all these local trees: They can only be changed on installation, cf. Changing the location of auto-installed packages in MiKTeX, and they cannot be disabled (by temporary removing from the MiKTeX roots).

For additional information see Difference between administrative and user mode of MiKTeX.

9
  • With my old MikTeX, I need to use --user-roots instead of --register-root. The good choice can be known by using initexmf --help.
    – projetmbc
    Sep 2, 2012 at 13:06
  • 1
    in my case, i tried to register roots using the settings manager. This created hickups. initexmf --update-fndb --verbose showed, that my new roots were ignored for some reason. Therefore i encourage everyone to add roots via command line and check fndb updates using verbose...
    – helt
    Aug 15, 2016 at 5:09
  • I got an internal error, so I ended up just plasing the .sty file in the same directory as the .tex file. MiKTeX encountered an internal error. Source: Libraries\MiKTeX\Core\Session\texmfroot.cpp Line: 925
    – Damian
    Dec 17, 2016 at 11:02
  • In my case, I had to create two additional folders in the "localtexmf" folder for this to work, that is the "bibtex" and "tex" folders.
    – BoZenKhaa
    Aug 28, 2017 at 11:48
  • 2
    With MikTeX 4.0.1 console, the "Roots" tab is now "Directories" Oct 10, 2020 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .