Feeds:
Posts
Comments

## New command and conditioning

To create a new custom command in LaTeX, the command \newcommand is well-known. Its full usage is:

\newcommand{\commandname}[n][d]{definition}


where

• \commandname is the name of the new command, with backslash; this name must have never been defined.
• n is the number of arguments of the new command; if ignored, there will be no argument.
• d is the default value of the first argument; if not provided, the first argument will be required.
• definition is the definition of the new command.

If the command name has already been defined, the above command will cause an error. To re-define a command, use \renewcommand instead.

## Conditioning

In the definition of the new command (or in your LaTeX document in general), you may want to generate content differently based on certain conditions. For example, if the first argument of the command is empty, you want to do “this”, otherwise you want to do “that.” You can use standard TeX commands (TeX programming) for this task, but it is easier to use the package xifthen (an extended version of the package ifthen, you can also use the latter if you want). These packages define commands like


\ifthenelse{condition}{code if true}{code if false}



and commands for checking conditions, for example \isempty{} to check if something is empty.

As an example, the following command generates content differently based on its optional first argument:


\newcommand{\mycommand}[2][]{%

\ifthenelse{\isempty{#1}}%

{\ensuremath{{#2}_{\mathrm{on}}}}%

{\ensuremath{{#2}_{\mathrm{on}, {#1}}}}%

}



Usafe examples:

• \mycommand{f} produces $f_{\mathrm{on}}$
• \mycommand[i]{f} produces $f_{\mathrm{on}, i}$

Read Full Post »

## Synchronization with SyncTeX

I wrote this post on my main blog a while ago. I copied it here because I think it’s more appropriate.

SyncTeX is a method for synchronization between (La)TeX source and its DVI/PDF file.  It is well and officially supported in TeXLive 2008. More information on using SyncTeX on Mac OS can be found here. This post targets Emacs+AucTeX (excellent LaTeX editor) and Skim (excellent PDF viewer) on Mac OS. Carbon Emacs (i.e. Emacs for Mac OS) can be downloaded from its website or from Apple’s website. Skim is located here.

Assuming that you already have Skim and Emacs+AucTeX up and running, this is how you enable SyncTeX in your LaTeX files and synchronize between them and their PDF files:

• To enable SyncTeX in your LaTeX files, first you must have TeXLive 2008 (or any TeX distribution that supports SyncTeX) installed in your system. When you compile your LaTeX files, use the switch -synctex=1 in your call to latex. Alternatively, you can add a line \synctex=1 in the preamble of the master TeX file. The PDF file compiled from your LaTeX source will be accompanied by a SyncTeX file of the same name, which contains information necessary for the synchronization.
• In Emacs, you must start the Emacs Server by issuing command server-start (M-x server-start <ENTER>).
• You must configure Skim to synchronize with Emacs: menu Preferences/Sync/Preset to Emacs.
• Open the PDF file in Skim. In Skim, hold Shift-Apple and click on any text in the PDF to go directly to the corresponding LaTeX source in Emacs.

That’s easy!

Read Full Post »

## To-do Notes in LaTeX

Found this useful post on the internet: http://kwarc.info/blog/2009/07/01/shiny-and-productive-to-do-notes-in-latex/

Copied:

I found the ultimate setup for to-do notes in LaTeX (of which my current thesis draft has a lot). Traditionally, I’ve been using Michael’s ednotes, but they didn’t look nice and they destroyed the page break by creating footnotes when enabled. Then, I switched to Henrik Skov Midtiby’s todonotes, which look great (thanks to TikZ), create a nice summary listing, and use the margin to preserve the page break. The only thing that’s missing is the possibility to annotate a complete range of text, which Michael’s ed package supports by the oldpart/newpart environments – and which he has recently spiced up with some color. So here is how to load both packages:

\usepackage{savesym}
\savesymbol{todo} % occurs in both packages
\usepackage[show]{ed}
\restoresymbol{ed}{todo} % now available as \edtodo
\usepackage{todonotes}

Read Full Post »