Have fun!

Drawing diagrams.

See my journal entry on Inkscape.

Right-aligning some text in an equation environment (like equation number).

To achieve, for example,


\begin{align}
V & = \frac 1 r \tag{3 dimensions} \\
V & = \log r \tag*{2 dimensions}
\end{align}

the following code was used:

\begin{align}
   V & = \frac 1 r \tag{3 dimensions} \\
   V & = \log r \tag*{2 dimensions}
\end{align}

The star controls whether or not parantheses are added. Note that these tags replace equation numbers (and in fact a numbered equation essentially has a \tag with the equation number inserted just before the \\ by default).

See this StackExchange question about using this with numbering.

Float placement.

LaTeX has a cunning way of placing floats in documents which very commonly ends up with them all failing to get processed and getting dumped at the end of the document (occasionally, there are "too many unprocessed floats" and LaTeX stops working altogether). Attempts to fix this often descend into all-out wars with the software involving tweaking text until everything just happens to work.

Basically, you can sort out most issues just by understanding how the float placement rules actually work. Typically, we modify the \begin{figure} declaration with an optional argument to indicate where LaTeX is allowed to place the float. For example, \begin{figure}[tb] would allow LaTeX to place the float at the top or bottom of a page. The following are the possible placement specifiers:

  • h ('Here if possible'): This attempts to place the float approximately at the location it appears in the source document (but not exactly).
  • t ('Top of page'): Try and place the float at the top of a page (this page or a later page). LaTeX has specific internal rules about whether it is allowed to place a float at the top of a page: by default, only floats occupying less than 70% of the page can be placed at the top of a page.
  • b ('Bottom of page'): Try and place the float at the bottom of a page. By default, only floats occupying less than 30% of the page can be placed at the bottom of a page.
  • p ('Page of floats'): Allocate a page for floats. By default, this is only allowed if at least 50% of the page would be occupied by floats.
  • ! ('Ignore LaTeX rules'): This overrides the default rules described in the above placements (but doesn't specify a specific location for the float).
  • H ('Here definitely'): This option requires the float package, and forces LaTeX to place the float exactly where it appears in text; essentially, this stops it being a float. Be careful, as the float may well overrun the end of a page or something if you do this.

In the absence of the H code, LaTeX determines where to place a float by first seeing if h, t, b and p work in that order on the current page; then, if that fails, it moves on to the next page, and so on.

Using footnotes in framed environments.

The framed package is very useful for decorating a LaTeX document, but it is incompatible with various other environments, perhaps most problematically footnotes[ref]. I first discovered this when I had a problem with vanishing footnotes in some environments (theorems, definitions and so on) which I had framed. To stop footnotes disappearing whilst still using the framed package, I came up with this (admittedly hacky) set of code for the preamble:

\makeatletter

\newcommand\mystuff@footnotebuffer{}
\newcounter{mystuff@footnote}

\newcommand\bufferfootnotes{%
	\let\mystuff@footnoteold\footnote%
	\setcounter{mystuff@footnote}{\thefootnote}%
	\renewcommand\mystuff@footnotebuffer{}%
	\renewcommand{\footnote}[1]{%
		\footnotemark%
		\g@addto@macro{\mystuff@footnotebuffer}{%
			\stepcounter{mystuff@footnote}%
			\protect\footnotetext[\themystuff@footnote]{##1}%
		}%
	}%
}
\newcommand\stopbufferingfootnotes{%
	\mystuff@footnotebuffer%
	\renewcommand{\footnote}[1]{\mystuff@footnoteold{##1}}%
}

\makeatother

To use this, you just need to surround the \begin{framed} and \end{framed} tags - or whatever - with the \bufferfootnotes and \stopbufferingfootnotes routines:

Text with normal\footnote{Honest!} footnotes.
\bufferfootnotes
\begin{framed}
Hello! I can\footnote{With the same command and syntax} use
the footnote command\footnote{Just like this.}.
\end{framed}
\stopbufferingfootnotes
More text with footnotes\footnote{Which are correctly numbered}.

Caveats

  • You may need to remove the \makeatletter and \makeatother if this code is already inside an environment where @ is treated like a letter. The reason this is used is so that we can hide lots of internal macros with prefixes starting mystuff@ and not be too worried about clashes. You can change the 'mystuff' prefix to whatever you like.
  • You cannot use the optional argument to specify the footnote index, as in \footnote[4]{This will be numbered as 4}, with the above code, though it could be modified. Also, it will not work if the numbering of footnotes is adjusted between the buffering commands, though this could probably also be fixed.
  • The hyperref package can provide links from footnote marks to the footnote's location, but this does not work with the above code. You could try to modify the above code by setting \Hy@footnote@currentHref appropriately (as in the hyperref readme), or simply load the hyperref package with the option hyperfootnotes=false (as in \usepackage[other options here...,hyperfootnotes=false]{hyperref}) to avoid creating any links for footnotes at all, which is what I do.

Useful LaTeX Tricks

Because great coders, like artists, copy

top / xhtml / css
© Carl Turner 2008-2017
design & engine by suchideas / hosted by xenSmart