21

Has anyone written, or is anyone working on, a LaTeX cookbook? Specifically, a guide to writing intermediate/advanced LaTeX macros and solutions to other common tasks?

I found a handful of resources on the Web, but these were all brief and basic and appeared to be written for beginners. I also found a document called "Advanced LaTeX", which looks good, but is only 23 pages, and is actually only intermediate rather than advanced.

I would love to have on my shelf a thick book that covers hundreds of short practical topics, with lots of visual examples.

Things I have wondered how to do—and eventually learned thanks to folks here who have kindly answered my questions—include:

Symbols

  • Using \ooalign to stack glyphs for finely-tuned custom symbols.
  • Creating custom symbols with TikZ when a symbol can't easily be created by mixing existing symbols.
  • Extracting a single glyph from a font without loading the font to use in a macro.
  • Patching \verbatim* and \verb* to override a symbol.

Styles

  • Testing whether the current style is slant or italic.
  • Using \mathchoice to ensure a macro displays properly in various math contexts.

General

  • Using \makeatletter and \makeatother for internal sub-macros.
  • Detecting an optional argument inside a macro.
  • Extracting specific characters from a macro argument string.
  • Using \futurelet to query the next token.
  • Using \ifthenelse to select different behaviors within a macro (I didn't even know about the ifthen package until yesterday, and I wish I'd known about it weeks ago).
  • Using \fbox to debug heights, depths, and width issues.

Formatting

  • Custom vertical and horizontal spacing in the tabular environment.
  • When and how to use \parbox.
  • Subtle differences between \hbox and \mbox.

Words

  • Right and wrong ways to suppress ligatures within a tricky word (such as "shelfful" or "cufflinks").

Many of these things turned out to be easy, but some (like \mathchoice, \ooalign, and \futurelet) were difficult if not overwhelming at first attempt. Most common questions seem to have answers here on TeX.sx already, but the answers can be elusive when the magic word or phrase to search for is not known, or when the possibility itself is not known (I totally didn't know about TikZ/PGF, for example).

lockstep
  • 250,273
Todd Lehman
  • 13,912
  • 1
    "(I didn't even know about the ifthen package until yesterday, and I wish I'd known about it weeks ago)" No, really you don't, trust me:-) It's OK for quick top level branches that are only going to be made once or twice in a document, but you don't really want to use it embedded in a macro set as it spends 99% of its time trying to offer an infix top level syntax that you don't really care about in internal code. – David Carlisle Feb 03 '12 at 15:58
  • @DavidCarlisle: Interesting. So what is a better TeX/LaTeX2e alternative? (Perhaps I need to go back and read more about the types of expressions allowed within \if\else\fi. It's not the if-then-else part of \ifthenelse that I found so seductive; it was the ease with which strings could be compared using \equal. But again, I probably need to read more about lower-level TeX.) – Todd Lehman Feb 03 '12 at 16:06
  • Not a duplicate: http://tex.stackexchange.com/questions/20549/a-cookbook-in-latex :). Is there a specific reason you tagged this {[tag:texniques]}? I'm afraid this might be a meta-tag, which are not everybody's favorite tags, to put it carefully. How about {[tag:learning]} and/or {[tag:tutorials]}? – doncherry Feb 03 '12 at 16:09
  • 1
    \equal isn't a lot more than \def\xxx{#1}\def\yyy{#2}\ifx\xxx\yyy yes \else no\fi Perhaps I'm hard on ifthenelse but 2 decades later I still feel the pain of trying to take the syntax as given and making it do anything useful without locking up a 0.5M 386 PC for days on end:-) – David Carlisle Feb 03 '12 at 16:11
  • 1
    LaTeX Hacks: Tipps und Techniken für professionellen Textsatz by Anselm Lingnau. It's in German but is readable with bit of google translate. Most of the cookbook formulae though are in the hundreds of packages on ctan. So far I have collected over 700 pages of notes on LaTeX and friends. – yannisl Feb 03 '12 at 17:06
  • @DavidCarlisle: Oh! So to compare, for example, \f@shape to the string it, one could \def\foo@it{it} and then \ifx\f@shape\foo@it{Yes}\else{No}\fi? Nice! – Todd Lehman Feb 03 '12 at 17:08
  • 1
    @YiannisLazarides: Nice! Do you have these notes published anywhere on the web? Or links organized? – Todd Lehman Feb 03 '12 at 17:09
  • @ToddLehman No I haven't put them on the web (as they are not in a very good shape). It is my intention sometime this year to do so. – yannisl Feb 03 '12 at 17:19
  • @yiannis l: if i had 700 pages of notes on anything, they would be no use to me, at all, without some pretty powerful searching technology. how on earth do you find things? (or are you looking for someone to publish your book manuscript ;-) – wasteofspace Feb 03 '12 at 17:23
  • 3
    @anon They accumulated over time and \index is a powerful command:) I want to edit them and publish on the web as a Free ebook, later on in the year. – yannisl Feb 03 '12 at 17:32
  • The UK-FAQ is a cookbook for normal users. – Leo Liu Feb 04 '12 at 08:02

3 Answers3

13

There's a LaTex wikibook which attempts to be something like what you describe. I've found it very useful in the time it's been around, and recommend it highly.

FWIW, I'm not connected to the project in any way, just a happy reader.

jimwise
  • 246
7

Yes, there is a 378 page book titled "LaTeX Cookbook" published by PACKT Publishing (2015) written by Stefan Kottwitz. I downloaded the free sample ebook edition, and based on the table of contents, it looks like an excellent resource.

user12711
  • 2,753
2

Tim Arnold tried to get one kind of cookbook to go but it never took off. Too bad.

Jim Hefferon
  • 4,476