LaTeXify C/C++ code snippets

26/01/2016

So I’m still writing lecture notes. This time, I need to include kind of larger pieces of C or C++ code, and \LaTeX environments do not really help me a lot. Some are better than others, but you still have to escape and fancify text yourself. This is laborious and error-prone, and is an obvious target for automation. A script of some sort. The task isn’t overly complicated: highlight keywords, and escape symbols like { } _ and & that make \LaTeX unhappy. This looks like a job for
sed.

Read the rest of this entry »


Search all your Bibtex files

12/01/2016

When I write papers or other things, I tend to create separate bib files, so that I don’t end with a giant unsearchable and unmaintainable blob. Moreover, topics tend to be transient, and the bibliography may or mayn’t be interesting in a few year’s time, so, if unused, it can safely sleep in a directory with the paper it’s attached to.

book_stack

But once in a while, I need one of those old references, and since they’re scatted just about everywhere… it may take a while to find them back. Unless you have a script. Scripts are nice.

Read the rest of this entry »


Yet more LaTeX indexing woes

21/04/2015

Still more indexing woes. LaTeX indexing, while superficially easy to use, turns out to be rather finicky, especially for anchor placement—that is, where the index (hyper)link actually points to.

index-woes

Let’s see what I have found to circumvent some of the difficulties.

Read the rest of this entry »


Beauxindex

07/04/2015

Last week I presented a simple script that helped spot almost identical index entries. Since then, I’ve sought a better index style. While I found most book use a rather plain index style, I was looking for something that used space efficiently yet was easy to read.

fancy-index

The idxlayout package will help us customize the index somewhat. It will allow us to set the number of columns, set the distance between them, maybe with a line, set font size, and decide how we want topics arranged. In the image above, I have used the singlepar layout. It is invoked by adding the itemlayout=singlepar option as a package option:

\usepackage[itemlayout=singlepar]{idxlayout}

With an extra bit of configuration somewhere else in your LaTeX source:

\renewcommand{\see}[2]{\mdseries \emph{\seename} #1 }
\renewcommand{\indexsubsdelim}{~\raisebox{0.2ex}{\resizebox{1em}{0.5ex}{$\sim$}}
} % symbol(s) between subtopics 
\setkeys{ila}{columns=3} % nb columns
\setkeys{ila}{rule=0pt} % width of line between cols (0=no line)
\setkeys{ila}{columnsep=1em} % spacing between columns
\setkeys{ila}{font=footnotesize} % base font size
\setkeys{ila}{indentunit=1em} % how much to indent after first line
\setkeys{ila}{justific=standard} % raggedright is a mess!
\setkeys{ila}{initsep=0.5em plus 0.5em minus 0.1em} % rubberband length between paragraphs
\printindex

The idxlayout package isn’t very well documented, so you might have to dig in the source code itself to find values that you’re interested in changing. It produces:

maths-discretes-index

Which appears… flat.

These tweak make a much better-looking index than the makeindex default, but there are still a few things to tweak. The thing that bothered me most is that we do not really have a clear separation between the head topic and subtopics. To achieve good visual separation, we must redefine yet more variables. This time in makeindex. However, makeindex customization involves an “index style” file:

\makeindex[options=-s back-matter/index.ist]

The configurable elements are found in makeindex‘s man page. The necessary elements are set in the index.ist file, as follows:

item_0 "\n \\bfseries \\item "
item_1 "\n \\mdseries \\subitem "
item_01 "\n \\mdseries \\indexsubsdelim "
item_x1 "\n \\mdseries \\indexsubsdelim "

The item_0 variable defines the style with which a topic will be displayed. For now, in bold. The item_xy variables define the style change when you go from a level x item to a y level item. Since I want subtopic to appear “normal face”, \mdseries is inserted just before the subitem. The item_x1 seems to be also necessary to ensure that only the first topic in a paragraph is bold.

The changes produce the index as shown in the image at the beginning


Checking a LaTeX Index

31/03/2015

This week again, LaTeX. This time, the index. At the end of a document, you will usually find an index so that, if you don’t have a magical ctrl-f, you can find something fast in the book.

maths-discretes-index

In LaTeX, creating an index is really easy. You include the package makeindex, and plant \index{topic!subtopic} tags in the text (preferably just besides the word you want to index, the \index command doesn’t understand paragraphs). You add \printindex somewhere else in your document and you run pdflatex (or just latex) to get the index generated. That’s all fine except that it doesn’t provide checks. It adds to the index whatever you typed, and doesn’t give warnings if you have an entry “compression” and an entry “compresion” (because, you know, typos happen). Let’s see how we can somewhat fix that.

Read the rest of this entry »


A LaTeX Bibliography Hack

24/03/2015

Yet another LaTeX hack! This time to insert text between the bibliography/reference header and the actual references. I’ve had, I admit, no really good reason to do this, as I might have added some text before the bibliography, but it made a lot more sense to include the paragraph there.

hack-bibliographie

Read the rest of this entry »


A (simple) LaTeX Example Environment

17/03/2015

This week again, a little LaTeX. As you know, I’m putting the finishing touches to a manuscript I’ve been working on for a little bit more than a year now. Those “finishing touches” always start simple, then end up asking for quite a bit more LaTeX programming that I’d like.

latex-example-detail

This week, I worked quite a bit to repair my “example” environment that include example number, extra margin, and a different colored box around the text. This helps locate and distinguish examples from normal text. But my first version had little problems. Like equations centered not on the example text but still relative to the whole page. Bummer. Let’s see how I fixed all that.

Read the rest of this entry »


X marks the spot

03/03/2015

I’m presently finishing a large text typeset in LaTeX. Of course, in many places I just put a note to “fill later” and moved on with the rest of the text. But now, I must hunt them down and fill the holes.

Good for me, I had the idea of writing a LaTeX command that not only marked the spot in the rendered page, like this:

fillme

…but also, by using the command itself, marked the spot in the source code itself. Otherwise, I’d have to find all the “fill me later” “add more” and whatnots.

The command itself is really not that complicated:

\usepackage{pifont}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\definecolor{bloodred}{HTML}{B00000}

\newcommand{\fillme}[1]{\textcolor{bloodred}{\smash{\ding{54}}}\message{Forgotten fillme on input line \the\inputlineno}} % 54 big fat X

The command takes an argument, which is ignored, but is quite convenient to leave the future you a message:

\fillme{blurb something about leibniz vs newton}

The command depends on the packages pifont for the dingbat and xcolor to define a nice dark red. The command itself does two things. One is to typeset a blood red X in the generated document so that it is conspicuous. The other is to output a message that can be parsed automagically by a script, making their eradication easier.


Un peu de caviar, s’il vous plaît

12/04/2011

There are times when you must hide information from a document without changing its appearance and layout. I’m not talking about plain censorship, I meant like when you have to submit a paper to a journal or a conference anonymously while required to follow stringent layout guidelines. It may suffice to set a background of the same colors as the text, but if it does the thing in print, it doesn’t work so well with PDF where you can still select the text (and I did a blog entry using this behavior a while ago).

There’s a censor package for \LaTeX but it doesn’t play well with whole paragraphs, and it messes out the layout if you select more than just a word or two. This week’s entry proposes a simple \LaTeX macro to do nice (but not weapon-grade) “censoring”.

Read the rest of this entry »


Asterisms in LaTeX

22/02/2011

Another \LaTeX trick this week: asterisms. Asterisms are typographic devices used to separate or to call attention to a piece of text without resorting to using a section or chapter. While its usage in modern English (and French, for that matter) is now rare, it is still an interesting device to structure text.

The usual manifestation of an asterism is the ⁂ symbol (U+2042) but the single character asterism may not be suitable for all occasion. In HTML, and in these posts, you have seen it quite often. With \LaTeX, getting an decent-looking asterism is not that easy.

Read the rest of this entry »