Sunday, August 5, 2012

One-keyboard-button compile your Google Drive-hosted Latex project

Context

First off, you already have your report on Google Drive and have made a compile-script, right? (See earlier post of how to set that up). 

Binding F2 to run the script

Let's say that "C:\thesis\build.bat" is the script that will download and compile your report. If we can bind one keyboard button to run that script (regardless of currently focused application) it could speed things up.

Here's how to beat Windows into running a .bat file by a key-press:

  1. Right-click on "Cmd" in the start-menu and "Send to taskbar" (making a shortcut among the Windows 7 speed-launch-icons)
  2. Shift-right-click the new cmd-icon in the taskbar and press Properties
  3. In "target" box append: /C "C:\thesis\build.bat"
    It should now say %windir%\system32\cmd.exe /C "C:\thesis\\build.bat" in the target-box. 
  4. In the keyboard-shortcut field select with mouse and press (for example) F2.
  5. [Ok]
Now pressing F2 at any time brings up a console windows with your build-script flashing by like a black-and-white Matrix scene, and the disappears. This is great for typing in the Google Drive document and having your pdf open on the other monitor in SumatraPDF which auto-refreshes the PDF when the file is updated.

Thursday, August 2, 2012

Auto-export URL references to Bibtex correctly in Medeley

The problem

Auto-exporting a bibtex file in Mendeley is nice and awsome when writing in Latex, but @misc URL references get their url in a \url tag, not in \howpublished{\url{...}} - which results in the URL not showing up in the References there when compiling the paper.

Solution

In Tools - Options - Document Details - [Web page], check in "Medium" (this is mapped to \howpublished in the exported Bibtex). (Tips: check in Citation Key also to control the \cite key)

Now, in your URL references, write, for example, "Available: http://www.example...." in the "Medium" field in the details pane of your reference. Now the URL shows up correctly in your paper (and is clickable)!


Thursday, March 8, 2012

Write LaTeX in Google Docs, compile locally to pdf

I want to write my MS thesis in LaTeX code, but also from anywhere via Google Docs.

This is how I automatically fetch and compile LaTeX code from Google Docs:

  1. Create the Google Docs document
  2. Put some LaTeX code in it. Hopefully you have some "boilerplate" code you always start with.
  3. (I assume you have a LaTeX compiler installed and know how to write in LaTeX)
  4. Install wget if you don't have it (Windows:  http://gnuwin32.sourceforge.net/packages/wget.htm, Other:  http://ftp.gnu.org/gnu/wget/)
  5. Press Share in your doc and allow anyone with the link to view it:
     
  6. Save. Copy the public link. Change the "/edit" in the end to only "/export?format=txt".
  7. Make a folder on your computer where you will be doing the LaTeX compilation.
  8. Make a script which downloads the doc as raw text file and then compiles it with the latex compiler.

This is how my download-and-compile script looks like:

"path/do/wget" "https://docs.google.com/doc..." -O thesis.tex --no-check-certificate
"path/to/pdflatex.exe" -interaction=nonstopmode "thesis.tex"

Those two lines are basically all it takes. When I run build_thesis.bat it downloads the very latest code and compiles it into a pdf.

Notes
  • Problems with the UTF-8 BOM sneaking in to the beginning? Try using lualatex.exe instead which supports UTF-8.
  • If you want to split up into many .tex files you can make many docs and wget all of them.
  • If you use images it's easiest to simply have them in your working folder.
  • Images in the Google Doc will be ignored in the raw text, so you can have your images in the doc and the code for LaTeX to compile them in for a nice preview.
  • A ToC in the doc follow as text in raw format, so it's best not to use it and instead rely on scrolling.
Tell me your results. Happy LaTeXing!

/Johan