TexPortable Manual

This page may be helpful for everyone who is interested in building his own portable package with the official sources or understanding the procedure of TexPortable. Or in order to get the latest versions of MiKTeX, Texmaker and SumatraPDF and bringing them together (- I guess I'm not able to update the package frequently, so this may be an option for you).

For a working LaTeX environment we need three different things:

  • a TeX distribution (this is the typesetting system itself, the base if you will),
  • an editor and
  • a viewer.

Here we are going to use MiKTeX as the TeX distribution. It is actively developed, stable, easy to use and more importantly the developer provides a portable package. But with MiKTeX itself we can't type anything, because it "only" contains the packages/components for LaTeX. Now we need some kind of an editor, preferably Texmaker, because of the possibility to set relative paths and customize a lot of useful other settings (like inverse search and some external PDF viewer stuff). Texmaker has its own viewer. So actually, there is no need for another viewer explicitly. But SumatraPDF is a fast and flexible PDF viewer which I recommend to use with this setup to make it more convenient when looking and browsing through the compiled document.

So, now we prepare the folders for each component and extract the files from each package we downloaded:

  • TexPortable (root folder)
    • MiKTeX
    • SumatraPDF
    • Texmaker

We have to place the launcher in our TexPortable root folder. This file will be called "TexPortable.exe" and is based on "TexPortable.ahk". It manages to start MiKTeX and Texmaker (if these are located in their respective folders).

TexPortable.ahk

This is the source code of the launcher file (TexPortable.exe).
It is written and compiled with AutoHotkey.

#NoTrayIcon
#SingleInstance force
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

param1 = "%A_WorkingDir%\Documents\Template\Template.tex"
editor = %A_WorkingDir%\Texmaker\texmaker.exe
texlib = %A_WorkingDir%\MiKTeX\miktex\bin\miktex-taskbar-icon.exe

IfNotExist, %editor%
  MsgBox, Can't find Texmaker.
    
IfNotExist, %texlib%
  MsgBox, Can't find MiKTeX.

Process, Exist, miktex-taskbar-icon.tmp
if Errorlevel != 0
{
  Run, "%editor%" %param1%
}
else
{
  Run, "%texlib%"
  Run, "%editor%" %param1%
}

IfWinActive, Texmaker ahk_class Qt5QWindowIcon
{
  ~F1::Gosub, activateTexmaker
}

WinWait, Texmaker ahk_class Qt5QWindowIcon
WinWaitClose
Gosub, closeMiktex
ExitApp

activateTexmaker:
  WinWaitActive, ahk_class SUMATRA_PDF_FRAME
  WinActivate, ahk_class Qt5QWindowIcon
  return

closeMiktex:
  WM_CLOSE=0x10
  WM_QUIT=0x12
  DetectHiddenWindows, On
  Process, Exist, miktex-taskbar-icon.tmp
  pid:=errorlevel
  IfWinExist, ahk_pid %pid%
  {
    WinClose
    ;PostMessage, WM_CLOSE
    ;PostMessage, WM_QUIT
  }
  else MsgBox, Can't find MiKTeX! Maybe you closed it already?
  return

Configure Texmaker

In Texmaker go to Options to configure the Texmaker commands. Each of the commands you want to use need to be adjusted.
Just insert ./MiKTeX/miktex/bin/ in front of these commands.

For example replace:
latex -interaction=nonstopmode %.tex
with:
./MiKTeX/miktex/bin/latex -interaction=nonstopmode %.tex

If we want to use SumatraPDF as an external viewer we need to change that setting as well. Set the commandline to:
./SumatraPDF/SumatraPDF.exe -reuse-instance %.pdf -forward-search #.tex @

We are almost finished now. We can start our launcher and Texmaker shows up, while MiKTeX is loaded in the tray. But there is a minor issue when we want to lookup something in SumatraPDF and edit this exact position in the LaTeX document (which is the inverse search feature). That is why (at long last) we need another file calling "pass.exe".

pass.exe?!

Unfortunately the inverse search feature (with SumatraPDF and Texmaker) only works if both executables are in the same folder. But I am no fan of mixing stuff up, sometimes it's better to keep things tidy and clean, so I created this file. It is a script which passes the command-line parameters (filename and linenumber) from SumatraPDF to Texmaker. The compiled version of this script must be kept in the same folder as SumatraPDF. The inverse search command line in the settings of SumatraPDF need to be set like this: pass.exe "%f" -line %l
Here is the source code of the file "pass.ahk":

#NoTrayIcon
#SingleInstance force
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

if 0 = 3
{
  Run, %A_WorkingDir%\..\Texmaker\texmaker.exe "%1%" "%2%" %3%
}
else
{
  MsgBox Sorry, I can only pass these 3 arguments to texmaker: "`%f" -line `%l`nA typo mabe? Or some crazy filename?
}

ExitApp

Well that's it! You can go ahead and start typing documents with LaTeX.

Upgrading MiKTeX/Texmaker/SumatraPDF

Upgrading the components can be done easily: If you want a new clean MiKTeX package, just delete the old one, and extract the new one into the same folder. But beware of losing your settings (mainly for Texmaker and SumatraPDF). You have to backup the corresponding files ("texmaker.ini" and "SumatraPDF-settings.txt" which are located in their respective subfolders) in order to keep and restore your settings.

Please feel free to contact me if you have any questions, feedback, or maybe suggestions for improvements.