Short version of the question

I need to automatically (not manually) install some packages that were not included after the installation of MiKTeX 2.9. I was able to solve this problem by following Leo Liu's responce, but this process is very manual... Is there a way to do the same, but using the command line? Or even better using a batch file or something similar?

Long version of the question

I am creating an automatic process to install MiKTeX and compile a .tex file to produce a .pdf document. This process would be used in our floor plant and implemented in all of our systems. Those systems run Windows 7 Professional 32-bit but do NOT have internet access. Which is why we have to bring all executables and required files in a USB-installer to the floor plant.

All the things I've tried so far:

  1. At first I though that if MiKTeX was installed with the option “Install missing packages on-the-fly:” set to Yes, it would do the trick. Unfortunately, this seems to only work if there is internet connection...
  2. Then I tried to create a local texmf tree in MiKTeX, as Speravir explains here, or several others explain too. Unfortunately, just like @user5751924 [1] and others, creating a "TDS compliant root directory" seems an impossible task... This goes in conjunction with trying to use the mpm (MiKTeX package manager) command [2], going also nowhere. In particular, the mpmcli_admin.log always says "Not a package repository" when I try for example:

    mpm --admin --install-some=list.txt --repository=C:\localtexmf

    Here, the "list.txt" contains (among others) the following packages that I need to install:

    • titlesec

    • fancyhdr

    • xifthen

    • xcolor

    • tikzpagenodes

    • grffile

    All those packages were manually downloaded and added to the USB-installer, in a fashion that should be TDS compliant, but clearly something is going wrong.

  3. I have also tried to consult the MiKTeX Manual but no luck there. I even looked at the PackageManager.cpp source code to try to understand what was the problem with my directory, but that was a dead end :(

  4. Finally, I did the manual install from @Leo Liu's responce, and it worked in one machine! But since this process needs to be done for hundreds of machines in the floor plant, the process must be automated. So his response doesn't help me too much.

How can I automate a process to do this using the command line? Using a batch file is also acceptable. Or any other help is extremely welcome!


PS. I'd be happy to provide any extra information if needed...

[1] Exact definition of a "local package repository" and exact associated procedures

[2] https://docs.miktex.org/manual/mpm.html

  • Join TUG and get the TeX Collection on DVD. I think you can even download it online (to put on a DVD), but I'm not sure if it works that way: tug.org/texcollection, with the proTeXt segment for a MikTeX-like installation: tug.org/protext. The page indicates "if you have plenty of bandwidth and want to burn your own DVD, you can download proTeXt as a giant ISO image." Disclaimer: While I have the TeX Collection DVD, I have not actually attempted an installation with it. Commented Oct 19, 2017 at 16:53
  • Thanks for your suggestion @steven-b-segletes, it's good to know that there is this option out there. Since I don't need "the entire" TeX Collection but rather the required packages and those few others, I prefer to install them myself. Besides our systems will only compile the report I created (and nothing else) so it is a very restricted environment for the use of latex here. And this is what I want. Again, thanks for taking the time to read my post and commenting. Commented Oct 19, 2017 at 18:46

1 Answer 1


graphicx is a required package. So there should be no need to install it.

To install the other packages

With a local repository

Get from CTAN the needed miktex packages from here


Most of the package are lzma-files, but there are also other formats.

Get also miktex-zzdb1-2.9.tar.lzma and miktex-zzdb2-2.9.tar.lzma. Ensure that all files are from the same ctan mirror so that the versions match.

Put everything in a folder (don't unpack the files!!) e.g. C:\localrepository. Then install them with

  mpm --admin --install-some=list.txt --repository=C:\localrepository

I can't know if the --admin switch is suitable for you. Without it mpm will install the packages in the USERINSTALL tree.

list.txt should contain a list of miktex-package names. So not hhline but tools (but this should be already installed), and not zref but oberdiek.

With a localtexmf

Get the packages from the same source. Create a C:\localtexmf. Unpack the packages in this folder (e.g. 7zip can handle the lzma). Check that all files are in the correct subfolder. E.g. xcolor.sty should be in C:\localtexmf\tex\latex\xcolor. You can view in the package manager of miktex in the properties of a package the correct path of every file:

enter image description here

When the localtexmf is correctly filled you can copy it to whatever location is suitable and attach it to a miktex system with

initexmf --register-root=C:\localtexmf

Again it depends on your actual setup if you should use --admin or not.

There are probably faster and more automatic ways to setup such a localtexmf (one can probably use mpm for it too) but imho a local repository is the more sensible solution anyway.

  • Thank you so very much for your response @ulrike-fischer. It is very useful and is helping to go in the right way. I still have so extra questions: Commented Oct 19, 2017 at 16:09
  • Here are the extra questions: 1. The link for CTAN packages does not have hhline. Any idea where I can find the lzma file for it? I really need this one on my .tex file! 2. The Package Manager keeps complaining about zref just saying "MiKTeX encountered an internal error" and points to line 656 of the PackageManager.cpp in the mpmcli.log file. I guess this is because it does not have the package info (by looking in the GUI). Any idea how to fix this? I'm using the "With a local repository" part of your response. Commented Oct 19, 2017 at 16:21
  • hhline.sty is in tools and should be already installed. Regarding zref: it is in the oberdiek package. Your list.txt should be a list of miktex names, not of styles or single files. Commented Oct 19, 2017 at 16:32
  • Thanks again Ulrike. I'm now looking in the MiKTeX Package Manager GUI to find what package contains each .sty file that I need (apparently there are a LOT more than I originally thought). Such a long and tedious task... but I hope at the end I can get all required packages I need installed. Commented Oct 19, 2017 at 17:07

You must log in to answer this question.

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