This page offers some scripts and recipes for creating a portable TeX setup, that you can take with you and run on an arbitrary Windows machine.
Since some configuration takes place, the word 'portable' is maybe not quite justified. However, only per-user settings are changed, and files are only placed in the user's private area.
MikTeX 2.5 Howto
This recipe creates a MikTeX 2.5 installation for either an external disk or a cd/dvd. A script in the root of the tree configures the host system for this MikTeX. It creates only per-user settings and only writes to your private area on the host system:
- Install MikTeX on your local disk. Do a private installation if you have a choice.
- Pick/create a directory; the root of your external drive, a subdirectory on this drive, or the drive that you are going to burn on cd/dvd. We shall call this directory the portable root.
- Copy the main MikTeX tree to the portable root. This copy should be called texmf and should be a direct subdirectory of the portable root.
- Optional: do the same with the localtexmf tree if it contains anything significant. The texmf- and localtexmf directories should be at the same level.
- If you configured e.g. some non-default languages or a non-default paper size, copy the resulting configuration files to the right place in the localtexmf tree. For a private installation, this is everything under C:\Documents and Settings\<user name>\Application Data\MikTeX\2.5. For a shared installation, look under C:\Documents and Settings\All Users\Application Data\MikTeX\2.5. You can copy the whole thing, but probably the only files that matter are under tex\generic\config. These files have to be copied to the analogous locations under the localtexmf tree.
- Copy mk_portable.vbs to the portable root.
- Optional: copy TeXnicCenter to the portable root. It will configure itself semi-automatically the first time you run it on any machine. Later versions require certain DLLs in the Windows system directory, so maybe you are better off with an older version; see the TeXnicCenter website.
- If applicable, burn to cd/dvd.
Now, whenever you want to use your portable MikTeX on a new machine, doubleclick mk_portable.vbs, and you can use your MikTeX from the command-line and from TeXnicCenter (if you did step 7), maybe after a re-login.
Since the MikTeX 2.5 filename database contains hard-coded paths, there is no good way to use a pre-generated filename database residing on your portable MikTeX disk. This may change in future versions of MikTeX.
TeXLive2007 Howto
TeX Live 2007 is almost but not quite suitable for portable use. The main obstacle is the use of the root of the C: drive as 'home'. Possibly, the next edition will make at least the script unnecessary.
- As in the MikTeX recipe, pick/create a portable root.
- Unpack some subdirectories from the TeX Live dvd in this directory. You need the bin, perltl, texmf and texmf-dist directories. If you have room, also add texmf-doc. You can save some space by not copying the entire bin subdirectory, but only bin\win32.
- Optional but highly recommended: install Ghostscript somewhere and copy its directory to the portable root. You should end up with a directory gs at the same level as texmf etc. above, with subdirectories gs\fonts and e.g. gs\gs8.56
- Optional: copy your texmf-local subdirectory to the portable root if it contains anything useful. The regular installer wants it one level higher, but the script will configure the host system to look for it at the same level as the other texmf trees. It should contain an ls-R filename database in its root.
- Copy tl_portable.vbs to the portable root. Check the last few lines of the script whether you want to add or change any fmtutil commands.
- Optional: copy an editor such as TeXnicCenter to the portable root. See the remarks under the MikTeX recipe. When TeXnicCenter tries to configure itself, you may have to tell it where to find the TeX Live binaries.
- If applicable, burn to cd/dvd.
Notes
The above scripts/recipes have been tested with Windows 2000 and Windows XP. A quick test with Vista showed that the scripts produce working versions of [pdf]latex and dvips. I have posted some general observations about Vista on this site.
Alternative implementation for MikTeX
On CTAN is another HOWTO which uses a set of batchfiles and the reg.exe command-line utility.
Documentation on MikTeX configuration
The MikTeX Preview document has information on registry entries and the location of generated files.
At installation time, you can give yourself a bit more control by creating a file setupwiz.opt, which is documented in the MikTeX manual; use the index to find this. You can put this file in the same directory as the setup program.
Home
Environment variables HOME and HOMEDRIVE are predefined under Windows 2000 and Windows XP, but as far as I can tell they are only used to define a default directory for the command prompt. For all practical purposes, the USERPROFILE directory is the real home directory of a user. This variable may have a value such as C:\Documents and Settings\user_name. In a roaming profile setup, this directory will be copied to a network drive on logout and back to the local drive on login. Some networks are configured to place USERPROFILE directories on a network drive to begin with. Anyhow, users are guaranteed to have write access to this directory. USERPROFILE is also predefined.
The registry
Windows stores almost all configuration in the registry, which is a database spread out over several files. User-specific settings are stored in a file %USERPROFILE%\NTUSER.DAT.
Environment and search path
Environment variables can be either per-user or per-system. Per-user environment variables are stored in the per-user part of the registry. In most cases, per-user settings seem to have priority over per-system settings. The search path is an unfortunate exception: it is concatenated from the system search path followed by the user search path.
If you don't want to change system-wide settings, then a pre-installed TeX on the system path will always be found first. It is still possible to create or modify a search path arbitrarily for a single session within a command prompt, and this will presumably be inherited by programs started up from this command prompt. Both installers will bail out if they find a different TeX on the system searchpath.
Choice of language
A scripting language for an installer script must first of all be available. That means either including it in the installation or using something that is guaranteed to be present. The language must also have some access to the internals of the operating system and to the registry, and have some string handling abilities.
I picked Windows Script Host with VBscript. Some people may only know it as a web scripting language, but VBscript can also run standalone. Although it has extremely limited GUI facilities and some strange omissions, it was capable of doing the job. JScript appears to have equivalent capabilities.
Finding TeX
Configuring TeX mainly requires knowing where it is in the file system. The installer will deduct its location from its own location. With this knowledge, it can create the necessary registry settings (MikTeX) or environment variables (TeX Live) - which are also stored in the registry. The installer will append the TeX binaries directory to the user searchpath.
Dealing with pre-installed software
A pre-installed TeX. Another TeX on the system searchpath can't be overruled with user-level settings, so in that case the install script will just bail out with an explanatory message. If there are other TeXs on the user searchpath then the install script can and will remove them from there.
Perl (TeX Live only). The install script tries to find a pre-installed copy of Perl and to give it priority over the version which comes with TeX Live. The PERL5LIB environment variable will only be set if there is no pre-installed Perl.
Ghostscript (TeX Live only). The install script tries to find a pre-installed copy of Ghostscript by searching the path and by searching appropriate registry keys. If no pre-installed Ghostscript is found, it will check whether a Ghostscript was included on the TeX Live disk. If found, Ghostscript is added to the searchpath and appropriate environment variables will be set. If Ghostscript isn't found, then the install script will print a warning message but continues.
Generating formats and other files
Several commands must be given in a certain order. In the case of TeX Live, some environment variables must be set before files can be generated. I did this by running an on-the-fly created batchfile.
Network installation
Installing TeX without system-level changes is also useful for a network setup: TeX can be placed on a for users read-only network drive, and users can enable this TeX for themselves by simply running a script, even if they only have limited rights on their workstation. In a roaming profile setup, running the script once enables TeX for them on every workstation on the network.
I maintain a MikTeX installation for my department. I wrote the installer with the NSIS installer system, using the same principles. A companion CD can be used either for installing on disk or as a portable TeX. This installer contains many site-specific hacks and is therefore not suitable for general distribution. Instead, I wrote these scripts and recipes, which I hope to be more generally useful, if only as sample code to demonstrate the issues.
Warning about UNC paths. Olivier Croquette informed me
that UNC paths won't work. A quick test on Vista produced the
mysterious error message Execution of the Windows Script Host
failed. (Not enough storage is available to complete this
operation. )
He proposed adding the following
test:
' check for UNC path
if ( Mid(sTexRoot,1,2) = "\\" ) Then
Wscript.Echo "Can not install from a UNC path (\\...)" & vbNewLine & _
"Please map a network drive and start again." & vbNewLine & _
"This drive will have to be mounted for Miktex to work."
Wscript.Quit( 1 )
End If
The next day: a test on another virtual machine revealed no problems. Anyway, it won't hurt to create a mapping first.
Zero config TeX Live installation
The two scripts presented above are only sort-of portable. For TeX Live, a more genuinely portable solution would consist of an icon that, when clicked, would start up an editor frontend (Emacs, TeXnicCenter) with the right settings, from where the TeX installation could be run.
The format files could be pre-generated and included in texmf-local. In the case of e.g. Emacs, the on-the-fly batchfile which sets environment variables could be replaced with an Emacs startup file.
Watch out that you pick an editor frontend which can run without installation and which doesn't require Windows system components which may not always be available. For this reason, hang on to obsolete installers.
See A Free Software Live DVD for Statistics for an Emacs-based solution by Poti Giannakouros.
Copyright (C) 2007 Siep Kroonenberg
siepo at cybercomm dot nl
Last revised on September 10 2007