## Thursday, July 23, 2009

### Typesetting tilde or backslash

Typesetting a tilde in Latex or Xetex is not so easy. It's a reserved character (non breakable fixed width space) and \~ produces a diacritic. Typing this diacritic alone, i.e. \~{} still produces a tilde which is small and high above the base line. When you follow most of the recommendations in Latex books, you probably write tilde by $\sim$ or any other more complicated variant thereof to work in both text and math environment. This produces a tilde nice and big, not too high above the baseline. What you also see is the recommendation to write tilde in the verbatim mode. For me these two are still not acceptable because they usually switch the font and you really see that the font of it looks alien to the surrounding text. Why should I switch the font when I want to write a tilde in the text mode? I want to get a nice tilde in the normal font which is not a diacritic. Font designers strived to match the appearance of the tilde glyph to the rest of the font so why shouldn't I use it?

Fortunately, there is a macro for typing the kind of tilde I need: \textasciitilde{}. It is just not generally known. This produces a tilde in the text mode which uses the tilde glyph from the font just as the font designers shaped it. It's similar to the command \textbackslash{} which is more widely known for typsetting backslash in text mode.

When you are in text mode, use these commands and spread the word.

## Wednesday, May 20, 2009

### Phantomas command

Recently I have found that there is a useful TeX command \phantom{Phantom Text} which behaves just like it would typeset its argument except that nothing is typeset and there is a blank space of the corresponding dimensions.

When I have been using it I imagined it would be sometimes even more useful to have a command which can put some other stuff in the reserved space instead of the phantom stuff.

Luckily, some smart guys have already written such a command.

Here is a modified version of their minimal example which illustrates nicely the use of this command:

\documentclass{article}\usepackage{calc} % for the \phantomas command% The following command is a better version of \phantom and requires the "calc" package% Credits: Jean-Côme Charpentier & Scott Pakin% Source: comp.text.tex, "Phantom-ish command"% usage: \phantomas[l]{phantom words which will be overwritten}{with these words}% the optional parameter [l] says that the words "with these words" will appear aligned left to the reserved space% another optional parameter is [r] for aligning the words right% if no optional parameter is given, the words will be centred in the reserved space\newcommand*\phantomas[3][c]{% \ifmmode \makebox[\widthof{$#2$}][#1]{$#3$}% \else \makebox[\widthof{#2}][#1]{#3}% \fi }\begin{document}A long entry another long entry and our last long entry\par \phantomas{A long entry}{centred} \phantomas[l]{another long entry}{on the left} \phantomas[r]{and our last long entry}{on the right} $\sin^2 x + \cos^2 x = 1$\par $\phantomas{\sin^2 x + \cos^2 x}{f(x)} = 1$\par $\phantomas[l]{\sin^2 x + \cos^2 x}{f(x)} = 1$\par $\phantomas[r]{\sin^2 x + \cos^2 x}{f(x)} = 1$ \end{document}

## Wednesday, February 25, 2009

### First gloss line in italics (gb4e)

The solution is in the gb4e manual on page 7:

% first gloss line in italics:
\let\eachwordone=\it

### Table lines starting with square bracket

this one does not compile:

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
a & b \\
[c] & d \\
\end{tabular}
\end{document}

if required, one can specify the vertical gap between lines in a table using
\\[len]

LaTeX removed the newline and whitespace to interpret the table as having a \\[c] entry, and there exists no length "c".

So the solution is to write the initial square bracket into curly braces. This way it is not interpreted as the beginning of the optional argument of the newline command.

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
a & b \\
{[}c] & d \\
\end{tabular}
\end{document}

Thanks to Werner Grundlingh for showing me the problem source.