Configuring Texmaker USB With MiKTeX Portable

Note: this article was last updated on June 24, 2012, for users of Windows 7 only.

After a lot of trial-and-error — not to mention a wee bit of teeth gnashing, hair pulling, and weeping uncontrollably — I have finally managed to get Texmaker USB configured work with MiKTeX Portable. Since there is a relative dearth of information on this particular setup on the Web, I thought I’d detail the setup for anyone else trying to get these two programs to communicate. It’s a bit of work to set up, but the bonus is that it doesn’t require any batch files to run and each module can be updated independently. Also, in my opinion, it’s always good to know how your portable LaTeX setup is built, in the event you need to troubleshoot something down the road (and you will).

First of all, you need an empty USB drive. Then, download the following programs:

  • MiKTeX Portable – extract into the new folder you just made
  • Texmaker USB – extract into LaTeX Portable/miktex-portable/ (you’ll need to create a new directory for MiKTeX Portable)

When you’re done, you should have two subdirectories on your USB drive, one each for MiKTeX Portable and Texmaker USB.

USB Drive
    |_____MiKTeX
    |_____texmakerwin32usb

Then, go to http://pages.cs.wisc.edu/~ghost/ and download the latest version GSView (5.0 at the time of this writing). This file is a self-extracting executable archive. Save it to your computer. Rather than running the .exe file, use a program like 7-zip to extract the contents to your LaTeX Portable directory. Again, you’ll need to create a new directory for the archive to extract the files into. When you’re done, your folder structure should look something like this:

USB Drive
    |_____GSView
    |_____MiKTeX
    |_____texmakerwin32usb

For Ghostscript, I recommend going to the PortableApps website and installing The PortableApps.com Platform to your USB drive. Once you’ve done that, launch the platform and open the menu. Click on ‘Apps,’ then ‘Get More Apps.’ Under ‘Utilities’ locate Ghostscript, select the checkbox, and click ‘Next.’ The PortableApps.com Platform will automatically install Ghostscript to your USB drive (under PortableApps/CommonFiles). This will make it easy to update as future updates are released.

Your LaTeX Portable folder structure should now look like:

USB Drive
    |_____GSView
        |_____gsview
        |_____pstotext
    |_____MiKTeX
    |_____texmakerwin32usb
    |_____PortableApps
        |_____CommonFiles
            |_____GhostScript

Finally, download the latest version of Asymptote.

At least as of version 2.16, Asymptote no longer functions properly using this method to install to a USB drive. I have had no luck finding a workaround (or at least, there’s no easy solution that doesn’t involve messing with drive letters or manually changing configuration options every time you plug the USB drive in to a computer). Instead, I recommend installing the TikZ and PGF package to MiKTeK and using TikZ for graphics, instead of Asymptote. You’ll have to learn a new language for building graphics, but the benefit is that you can compile everything in one go. I’ll leave the instructions for Asymptote here for the time being, in the event that something changes or someone is masochistic enough to insist on trying to make it work from a USB drive.

Save the executable and use 7-zip to extract the files to an Asymptote directory on your USB Drive. Your file structure should now look like this:

USB Drive
    |_____Aysmptote
    |_____GSView
        |_____gsview
        |_____pstotext
    |_____MiKTeX
    |_____PortableApps
        |_____CommonFiles
            |_____GhostScript
    |_____texmakerwin32usb

Optional Steps:

Since Texmaker now has a built-in viewer, installing a PDF reader like FoxitReader is no longer necessary. If, however, you still want to use an external viewer, use the PortableApps.com Platform to install Foxit Reader the same way you installed Ghostscript. Then configure your Texmaker settings to use an External Viewer with the following path:

Pdf Viewer "../PortableApps/FoxitReaderPortable/FoxitReaderPortable.exe" %.pdf

You can also install the R Project statistical package. (I may detail how to do this in a later article). If you do so, your file structure will look like this:

USB Drive
    |_____Aysmptote
    |_____GSView
        |_____gsview
        |_____pstotext
    |_____MiKTeX
    |_____PortableApps
        |_____CommonFiles
            |_____GhostScript
    |_____R
    |_____texmakerwin32usb

The step below will show you how to configure your settings to make use of R’s Sweave utility.

The next step is to configure Texmaker to access the MiKTeX Portable and Ghostscript/GSView files. Launch Texmaker, then click on Options -> Configure Texmaker. The Commands screen should pop up by default. We’re going to modify most of these fields so that Texmaker can process your .tex files while still being able to run from a USB stick on any Windows computer.

LaTeX: "../MiKTeX/miktex/bin/latex.exe" -interaction=nonstopmode %.tex
dvips: "../MiKTeX/miktex/bin/dvips.exe" -o %.ps %.dvi
Bib(la)tex: "../MiKTeX/miktex/bin/bibtex.exe" %
Makeindex: "../MiKTeX/miktex/bin/makeindex.exe" %.idx
Dvi Viewer: "../MiKTeX/miktex/bin/yap.exe" -1 -s @%.tex %.dvi
PS Viewer: "../GSView/GSviewPortable.exe" %.ps
PdfLaTeX: "../MiKTeX/miktex/bin/pdflatex.exe" -interaction=nonstopmode -synctex=1 %.tex
Dvipdfm: "../MiKTeX/miktex/bin/dvipdfm.exe" %.dvi
ps2pdf: "../MiKTeX/miktex/bin/ps2pdf.exe" %.ps
Pdf Viewer: Set this to use the Built-in Viewer (optional: Click the Embed checkbox)
metapost: "../MiKTeX/bin/mpost.exe" --interaction nonstopmode
ghostscript: "../PortableApps/CommonFiles/Ghostscript/bin/gswin32c.exe"
Asymptote: "../Asymptote/asy.exe" %.asy
Latexmk: "../MiKTeX/miktex/bin/latexmk.exe" -e "$pdflatex=q/pdflatex -interaction=nonstopmode/" -pdf %.tex
R Sweave: "../R/bin/R.exe" CMD Sweave %.Rnw

Set your QuickBuild to run PdfLaTeX + View PDF. Once you make these changes, your portable LaTeX setup should be all configured and ready to work on any USB stick.

Inverse Search

With the addition of Texmaker’s built-in viewer, configuring Inverse Search is no longer necessary. If you still need to do this, reference the link in the resource section below.

Update: This article has been updated to reflect my latest build method and software updates. Due to the influx of spambots, I’ve had to close the comments here, so if you have any questions, tips, or pointers for a better portable LaTeX installation, feel free to email me with your thoughts.

Additional resources:
GSview 4.9 and Ghostscript 8.60 Portable
“Forward/Inverse search” with Texmaker

  • Alan

    Were you able to make to get inverse dvi search from Yap back to TeXMaker to work?

    • http://reclaimercomic.com Jim Stitzel
    • http://intensedebate.com/people/stitzelj Jim Stitzel

      Alan, I've updated this post with the information you asked about. Hope it helps.
      My recent post 235 – Viral Anarchy

  • Alan

    Jim, thanks for going to the trouble of making such a detailed explanation. It helped a lot!! I think your web page editor may have automatically converted the upright quotation symbol that is needed in the command line arguments into slanted quotation symbols. Also, the double dash was converted into the long dash. So, copying and pasting doesn't work. I was not able to get the inverse search with Texmaker to work with either my regular hard drive install or with the USB install. I'm pretty sure I followed the instructions. Apparently other people have had that problem too. However, inverse search did work when I modified your instructions for TexmakerX. I spent a few hours experimenting with various configurations. It didn't even occur to me that Yap needed to be run in administrator mode. I discovered through trial and error, that occasionally,Yap can be given a relative path name and then inverse searching will work for a while, until something changes. I think the problem has to do with telling Yap how to set its current directory, but I didn't find an option for that. Also, I hadn't previous installed ghostscript, Ghostview, or a PDF viewer on my USB LaTeX distribution. Using 7-zip to extract the files from the executable files was a good idea! Since both forward and inverse search are really important to me when I'm editing LaTeX files, I also tried out your suggestions with the Sumatra PDF viewer. The forward and inverse searching from Texmaker and TexmakerX to Sumatra seems to work, except I was getting multiple instances of both the text editor and viewer. I'm getting closer to having a full fledged completely functional LaTeX environment on a USB memory stick with functional forward/inverse search for both dvi and pdf files. I have to say your post about USB LaTeX inspired me to do a lot of experimenting this weekend.

    • http://intensedebate.com/people/stitzelj Jim Stitzel

      Thanks for the heads-up on the formatting issue, Alan. I didn't even think about that. I converted those commands to preformatted text to preserve the format.

      As for the inverse search, it took me quite a bit of experimenting to figure out as much as I did, and even then it wasn't as smooth as I'd like to see. I had the same problem with the multiple instances that you mentioned and have, as yet, to find a way to correct that. If you come up with something, please let me know.

      Setting this portable version of LaTeX up has been something of a first for me, so I'm not surprised there's still a few kinks to work out. I'll update this post as I come up with anything new.
      My recent post 235 – Viral Anarchy

    • Goofy

      Can you please be a little bit more specific about which commands to change, thanks.

  • wt8008

    I've noticed that ps2pdf does not work because ps2pdf in ghostscript uses bat files for processing, most likely due to PATH not being what it should. I suggest using a bat file to start texmaker which temporarily changes PATH to include miktex-portable/miktex/bin, and restore on exit, such that the ps2pdf utilities do not run into issues. This also simplifies the texmaker path settings. The path variable change will only effect the command line instance that it is changed in, and not system wide.

    The other suggestion I have is to use sumatrapdf with the -reuse-instance command line option, to reuse the same window for the pdf, instead of opening a new one. I haven't tried doing forward and inverse search with sumatrapdf.

    • http://intensedebate.com/people/stitzelj Jim Stitzel

      Thanks for the suggestions. I'll definitely take a look into them and see what I can figure out.
      My recent post 236 – Crux

  • Peter

    Hi, when I download and unpack the ghostscript 8.64 .tar-archive there's no directory "gs864w32" and therefore no "gs8.64" and stuff either. Anyone knows what's up with this…?

    • http://intensedebate.com/people/stitzelj Jim Stitzel

      You should have downloaded the executable file. The file structure in the other archives is different.
      My recent post 240 – Pure

    • Peter

      Problem solved. Careful reading really for the better! ;-)

  • Pingback: Tutorial LaTeX – Geek Vault

  • Isaias

    How to compile Metapost whit Texmaker?. Thanks

  • Oscar

    Thanks man! This page was EXTREMELY HELPFUL!! :)

    • http://reclaimercomic.com Jim Stitzel

      Great! Glad you found it useful!

  • JMJáureguiG

    Great post ! ! ! =)
    It was just what I needed =D

  • Venkat

    Great post ,,, Now I can finally carry the full installation on a portable drive .. Cheers

  • benigurion

    It helped a lot, Thanks!!!!!!

  • katie

    Thanks for doing this, it's really helped.
    I'd been trying to sort it out myself for hours, found this and it's all working now! :)

    • http://reclaimercomic.com Jim Stitzel

      Glad it helped! This is far and away the most popular post on my site, so I'm happy that it continues to be useful!

  • Pete

    This is a fantastic post! I needed this write my masters dissertation so many thanks!

    • http://reclaimercomic.com Jim Stitzel

      Great! Glad it helped!

  • Anon

    Thank you VERY much for this tut !

    • Goofy

      Please share the light, its dark here. Says could not start the command.

      • Goofy

        Please

  • Ramona

    NICE – very well done – and most importantly: thank you sooooooooo much

    • Goofy

      Please, what are we supposed to change to make it run, keeps on saying could not start the command. Help please

  • Goofy

    Does it come with all the packages? If not how can i add them because there is a big problem adding packages with the latest addition of miktex

    • http://reclaimercomic.com Jim Stitzel

      I don't think it does. I haven't played with this setup in a while, so I don't know what new challenges there may be with recent iterations of miktex. I may have to play with it again at some point and see what's what.

  • Goofy

    Help, mine isn't working. I dont get what is wrong or what to change in the arguments.

  • Raphael

    Hi, I’m getting an error when using ps2pdf. It’s returning an error message saying that “mgs.exe” is not regonizable as an internal or external command. Could you help me please?
    Thaks a lot

    • http://jimstitzel.com Jim

      Hi, Raphael, I can’t replicate the problem, so I’m not really sure how to advise you. My best guess at this point is that you may need to change your paths to absolute paths so that your LaTeX editor can find everything. Relative paths can sometimes be a little dicey. Try making that change and see if it makes a difference.

      • M

        Hi,,
        I added the absolute path of the miktex/bin folder to the Add to PATH field in the texmaker config. I.e. “F:/MiKTeX/miktex/bin/”. Linking all the variables to absolute path, didn’t solved the problem for me.

  • Sarah

    An easier way is to download USBTex at http://146.163.152.131/teaching/USBTeX.zip and just unzip it to a folder on your hard drive. It has had MikTex, TexMaker, and a .pdf viewer. Enjoy!

  • Sarah

    I meant USB not hard drive.

  • meee

    Hey there,

    not sure if it’s still appropriate to reply to such an old posting, but I followed through your tutorial, and Texmaker also seems to run all right, but whenever I press the PDFLaTeX button, I get the message, that the Logfile can’t be found.
    Any idea what could be the matter?
    thx!

  • Tim

    Hey, I am having problems getting this to work with the new versions of MikTeX and TeXMaker. Having followed these instructions I click quick build and TeXMaker grays the button, waits a bit and then un-grays the button, but doesn’t seem to do anything to the pdf. Any ideas?