Category Theory
Zulip Server
Archive

You're reading the public-facing archive of the Category Theory Zulip server.
To join the server you need an invite. Anybody can get an invite by contacting Matteo Capucci at name dot surname at gmail dot com.
For all things related to this archive refer to the same person.


Stream: learning: questions

Topic: latex + CT


view this post on Zulip Bruno Gavranović (Mar 13 2022 at 16:14):

This is not really a question about CT, but about how to organize all the things relevant to writing CT in latex. It's also not a specific question, but more of an open ended one: I'm curious to hear about people's workflow's in latex.

How do you organise your latex macros, preambles, environments etc.? My workflow is a mess. Is there a "canonical" thing everyone does or does everyone have their own special preamble? Is there a (math) package you always include?
For instance, I've seen people use \newcommand for macros, but also \DeclareMathOperator.
I've also seen people write something like \cat C for a category, but also people writing things like \Ca, where \Ca is a macro for \mathcal{C} (but then you have to do it for every letter, which I've also seen people do). Maybe this doesn't matter, but I thought I'd just get a sense of what people here think/use, since I assume down the road it might be good to be consistent.

Also, any other latex tips you have! (I've realised down the road I'll have to start writing a thesis eventually, so it might be good to ask this before I start writing...)

view this post on Zulip Mike Shulman (Mar 13 2022 at 16:55):

Here's a trick in latex that does it for every letter automatically:

\makeatletter
\let\ea\expandafter
\def\foreachLetter#1#2#3{\foreachcount=#1
  \ea\loop\ea\ea\ea#3\@Alph\foreachcount
  \advance\foreachcount by 1
  \ifnum\foreachcount<#2\repeat}
\def\definecal#1{\ea\gdef\csname c#1\endcsname{\ensuremath{\mathcal{#1}}\xspace}}
\foreachLetter{1}{27}{\definecal}

One can argue about whether this is a better idea than writing a separate script in some other language to just spit out \newcommand{\cA}{\ensuremath{\mathcal{A}}\xspace} and its 25 friends...

view this post on Zulip Mike Shulman (Mar 13 2022 at 16:56):

Note the \ensuremath and \xspace, which lets you write things like

Let \cC be a category

without needing dollarsigns.

view this post on Zulip Ralph Sarkis (Mar 13 2022 at 17:31):

I dislike latex macros simply because I need to extend my pinky finger to press the backslash key, so for very common things that don't change between documents, I have macros set up in my editor. (e.g. typing mbf then enter writes \mathbf{} and puts my cursor in the brackets). However, this is not so great when working on long writing projects (e.g. a thesis) because you might change your mind on some macros and 'search and replace' is annoying (especially over multiple files) and sometimes impossible. Also, when working with coauthors, I prefer to use macros to easily get consistent results. All in all, I think my workflow is a mess too, but it is very flexible.

If I can suggest one package, I highly recommend the wonderful knowledge package, it slows you down a bit when writing (especially at the start), but your readers will be very pleased (I know I am when I read papers that use the package : examples).

view this post on Zulip John Baez (Mar 13 2022 at 17:53):

I think there's a choice of philosophy in these things, depending on whether or not you want your LaTeX code to be easy to read - for yourself, that is. What that means would vary from person to person I guess. I want my LaTeX code to be easily readable by me, since I spend a lot of time reading and rewriting it. So, for example, I want the macros for things to be unobtrusive. I use the real numbers a lot, so I use the macro \R which looks a lot like R\mathbb{R} (a symbol I have a lot of fondness for), not some other things I've seen people use, like \Real.

view this post on Zulip Mike Shulman (Mar 13 2022 at 18:03):

Ralph Sarkis said:

However, this is not so great when working on long writing projects (e.g. a thesis) because you might change your mind on some macros and 'search and replace' is annoying (especially over multiple files) and sometimes impossible. Also, when working with coauthors, I prefer to use macros to easily get consistent results.

I think this is a really important point. In my opinion the use of semantic macros (i.e. named by their mathematical meaning rather than by the visual results they produce) is an essential habit to get into.

I dislike latex macros simply because I need to extend my pinky finger to press the backslash key

The simple solution to that is to remap your keyboard to put the backslash somewhere else. (-:

view this post on Zulip John Baez (Mar 13 2022 at 18:18):

Switch it with the space bar. :stuck_out_tongue_wink:

view this post on Zulip Jules Hedges (Mar 13 2022 at 19:04):

Ralph Sarkis said:

I dislike latex macros simply because I need to extend my pinky finger to press the backslash key

Back in the good old days when I was writing LaTeX regularly (ie when I was a PhD student) I simply changed my keymappings to swap the \ and ; keys... like most programming languages LaTeX really isn't designed for a BrEn keyboard...

view this post on Zulip Bruno Gavranović (Mar 14 2022 at 00:16):

Mike Shulman said:

Note the \ensuremath and \xspace, which lets you write things like

Let \cC be a category

without needing dollarsigns.

Ah nice, I wasn't aware of this. I just googled about ensuremath and found that people report it breaks in some circumstances. Has this been your experience or would you say it's something that's always good to use?

view this post on Zulip Bruno Gavranović (Mar 14 2022 at 00:19):

Mike Shulman said:

Ralph Sarkis said:

However, this is not so great when working on long writing projects (e.g. a thesis) because you might change your mind on some macros and 'search and replace' is annoying (especially over multiple files) and sometimes impossible. Also, when working with coauthors, I prefer to use macros to easily get consistent results.

I think this is a really important point. In my opinion the use of semantic macros (i.e. named by their mathematical meaning rather than by the visual results they produce) is an essential habit to get into.

Does this mean that the prefix c in \cC`` in your latex trick above doesn't refer to mathCal`, bur rather to the fact that it's a symbol for a category?

view this post on Zulip Mike Shulman (Mar 14 2022 at 00:34):

I've never had any problems with ensuremath.

view this post on Zulip Mike Shulman (Mar 14 2022 at 00:35):

Bruno Gavranovic said:

Does this mean that the prefix c in \cC in your latex trick above doesn't refer to mathCal, bur rather to the fact that it's a symbol for a category?

No, I don't usually adhere to the principle of semantic macros for single characters. Possibly I should, but only rarely has it ever been a problem.

view this post on Zulip Mike Shulman (Mar 14 2022 at 00:37):

The problems with ensuremath noted at your link seem mostly to arise when putting it around a parameter passed by the caller. I don't think I ever do that.

view this post on Zulip Mike Shulman (Mar 14 2022 at 06:49):

Ralph Sarkis said:

If I can suggest one package, I highly recommend the wonderful knowledge package,

That package looks amazing! Thanks for the tip.

view this post on Zulip Matteo Capucci (he/him) (Mar 14 2022 at 16:13):

I semantically-macro everything, and when I don't I usually regret it.

view this post on Zulip Tom Hirschowitz (Mar 14 2022 at 16:37):

I'm more with @John Baez on the use of macros. In order to maximise readability of source, I use unicode extensively, with (my own fork of) Manu Beffara's ebutf8.sty to translate them to LaTeX. It is virtually almost as expressive as unicode-math + lualatex, the only drawback being that unicode accents do not work. And most importantly, you do not need to convert to plain LaTeX when submitting.

view this post on Zulip Mike Shulman (Mar 14 2022 at 18:03):

I didn't read John's comment as in opposition to semantic macros: one can still consider \R to mean "the real numbers" rather than "a blackboard bold R", with the option to change notation globally for the real numbers if needed.

view this post on Zulip Tom Hirschowitz (Mar 15 2022 at 08:02):

Fair enough. But the point is that unicode symbols are almost as flexible as macros: most of the time, it's safe to search&replace them, though arguably a bit more cumbersome than merely modifying a macro definition.

view this post on Zulip Jon Sterling (Mar 15 2022 at 08:46):

I think that single-letter identifiers are a bit of a grey area and although I am a diehard macro user, the damage caused by just using the symbol is not so bad (e.g. it doesn't degrade maintainability very severely). On the other hand, not using macros for composite notations makes a document essentially unmaintainable.

view this post on Zulip Fabrizio Genovese (Mar 15 2022 at 15:36):

Semantic macroing is fundamental. Also the tension between macros that mean something (e.g. \realNumbers) vs macros that are fast to type (\R) often comes to your editor. I use editors with autocomplete so I just have to type 2-3 chars and then tab, meaning that I can afford to use very long and legible macros without getting too slow

view this post on Zulip Fabrizio Genovese (Mar 15 2022 at 15:37):

I also have another definitely non-mainstream rule: All my macros start with a capitalized letter. In this way I risk zero overlap with LaTeX already defined commands and other people macros (almost no one does this).

view this post on Zulip Mike Shulman (Mar 15 2022 at 16:03):

I would argue that f : \R \to \R is more legible than f : \realNumbers \to \realNumbers.

view this post on Zulip Joe Moeller (Mar 15 2022 at 16:11):

I was actually thinking that to many mathematicians, the distinction being made for R\mathbb R in particular must be strange, because R\mathbb R means the real numbers as much as the words "the real numbers" do.

view this post on Zulip Mike Shulman (Mar 15 2022 at 16:22):

Yes, all the way through I've been thinking about the (possibly apocryphal) example of const PI = 3.14159 in a programming language manual that "makes it easier to modify the program, should the value of pi change".

view this post on Zulip Mike Shulman (Mar 15 2022 at 16:23):

Although there are other uses of R\mathbb{R} in the literature, e.g. Berger-Moerdijk use it to denote a Reedy category.

view this post on Zulip Jon Sterling (Mar 15 2022 at 16:53):

Fabrizio Genovese said:

I also have another definitely non-mainstream rule: All my macros start with a capitalized letter. In this way I risk zero overlap with LaTeX already defined commands and other people macros (almost no one does this).

I do this too! I can't remember who told me to do it but I think it is recommended practice.

view this post on Zulip Reid Barton (Mar 15 2022 at 16:55):

This isn't literally true right? off the top of my head there's \SS and probably \A and \O

view this post on Zulip Fabrizio Genovese (Mar 15 2022 at 17:55):

Mike Shulman said:

I would argue that f : \R \to \R is more legible than f : \realNumbers \to \realNumbers.

In my case I think I use \Reals. In any case the point is that I prefer descriptive macros more than easy to type ones.

view this post on Zulip Ralph Sarkis (Mar 15 2022 at 18:10):

I'd argue that after a while, any macro becomes descriptive. E.g.: \R and R\mathbb{R} are basically the same thing to me, similarly for most default macros that I use (\oplus, \otimes, \vdash, etc.). I even use some of them orally (maybe because I am not a native English speaker).

view this post on Zulip Mike Shulman (Mar 15 2022 at 18:13):

That's a good point about macros becoming descriptive. I used to have a macro \ten (for "tensor") for \otimes, but since I had to write out \otimes all the time anyway when writing math on the nLab, MathOverflow, and Zulip, I just fell into writing out \otimes in my LaTeX too. And as long as it's a single macro, if I need to change the symbol for tensor products I can just redefine it.

view this post on Zulip John Baez (Mar 15 2022 at 18:50):

Yeah, I used to have a macro \tensor to make my LaTeX more readable to me, but I think I've slipped into finding \otimes readable.

Lots of people don't know there's a visible difference in LaTeX between : and \colon, with the latter being correct for expressions like f \colon \R \to \R. For readability I use \maps to mean \colon, since f \maps \R \to \R is just like how I talk.

view this post on Zulip Mike Shulman (Mar 15 2022 at 19:18):

John Baez said:

Lots of people don't know there's a visible difference in LaTeX between : and \colon, with the latter being correct for expressions like f \colon \R \to \R. For readability I use \maps to mean \colon, since f \maps \R \to \R is just like how I talk.

I used to believe that too. But then when I started doing type theory, I realized that the colon in f:RRf:R\to R is just an instance of the colon in a typing judgment, and there are lots of cases where I think using \colon for a typing judgment looks wrong. So now I use : for everything, and as a bonus my source code is more readable.

I wonder who it was who decided that they get to decide what the "correct" spacing of a colon is.

view this post on Zulip John Baez (Mar 15 2022 at 19:21):

Knuth? But I agree with him: I don't like the equally wide spaces in f:RRf : R \to R, I like f ⁣:RRf \colon R \to R.

view this post on Zulip John Baez (Mar 15 2022 at 19:22):

I like the equally wide spaces in something like {x:x23} \{x : x^2 \ge 3\}.

But I'm obviously not a typist (= type theorist). I have never knowingly written a paper that says x:Xx : X to mean "xx is of type XX".

view this post on Zulip Mike Shulman (Mar 15 2022 at 20:04):

But when you write f:RRf : R \to R, it means "ff is of type RRR\to R."

view this post on Zulip Martti Karvonen (Mar 15 2022 at 20:31):

Mike Shulman said:

I would argue that f : \R \to \R is more legible than f : \realNumbers \to \realNumbers.

Let alone \FnDeclaration{f}{\Reals}{\Reals} , in case you want the option of replacing : with \colon or \to with \longrightarrow or something.

view this post on Zulip John Baez (Mar 15 2022 at 20:57):

Mike Shulman said:

But when you write f:RRf : R \to R, it means "ff is of type RRR\to R."

Yeah, I get it. That's one way to read it, but I never write XYX \to Y as the name of a type, so I don't think the sentence "ff is of type RRR\to R" when I see f:RRf: R \to R . Sorry, I'm one of the old-fashioned guys who will be left in the dustbin of history.

view this post on Zulip John Baez (Mar 15 2022 at 20:58):

More importantly:

I just accidentally noticed that here on Zulip $$\R$$ produces this: R\R.

view this post on Zulip John Baez (Mar 15 2022 at 20:59):

Is \R a built-in LaTeX macro for the real numbers? If so, I didn't know that.

view this post on Zulip Evan Patterson (Mar 15 2022 at 21:25):

I don't think so. At least, I've added that macro to the preamble of just about every paper I've ever written!

view this post on Zulip John Baez (Mar 15 2022 at 21:59):

So maybe someone did it on Zulip.

view this post on Zulip Nathanael Arkor (Mar 16 2022 at 12:12):

KaTeX appears to render \R as R\R (I'm not sure for what reason), which is why Zulip does too.

view this post on Zulip Matteo Capucci (he/him) (Mar 17 2022 at 08:57):

Ralph Sarkis said:

I even use some of them orally (maybe because I am not a native English speaker).

lmao this really hits home... in the paper i'm currently writing we are using like 3 different monoidal products so we just call them with their latex name (though in the doc each use has its own semantic macro associated :nerd: )

view this post on Zulip Matteo Capucci (he/him) (Mar 17 2022 at 09:00):

I didn't know about \colon being different from :... I hate the spacing around : when it comes to denote typing judgments, in my thesis i've defined something like \tin aliased to \!:\! to make it tolerable

view this post on Zulip Fabrizio Genovese (Mar 17 2022 at 12:41):

For sure using the same macro again and again makes it readable, we humans are amazing at picking up patterns. You could also use \Charles or \Bob to define the real numbers, after enough using that would be perfectly ok for you.
It becomes more difficult when you want to make your code

Indeed, we are amazing at picking up patterns but also at forgetting them when we do not exercise enough. So I do stick with descriptive macros for these reasons. It may happen that I introduce some notation for some work, then stop using that notation for a few years, and then come back to that line of work again. That is the situation when naming, say, the reals \Bob and \Charles is going to turn your workflow into an unpleasant one.

view this post on Zulip Fabrizio Genovese (Mar 17 2022 at 12:42):

But then again, this is just my opinion. These choices are very personal as it is the choice of the editor one uses, and who am I to judge.

view this post on Zulip Mike Shulman (Mar 17 2022 at 17:48):

I don't think anyone is going to stop using the notation R\mathbb{R} for the real numbers.

view this post on Zulip John Baez (Mar 17 2022 at 18:57):

Yes, : is designed to have big equal-sized spaces on both sides:

: \square :\square

\colon is designed to be asymmetrical, with less space at left:

 ⁣: \square \colon \square

view this post on Zulip Fabrizio Genovese (Mar 17 2022 at 21:42):

Mike Shulman said:

I don't think anyone is going to stop using the notation R\mathbb{R} for the real numbers.

I don't see what this has to do with my argument tho. I am arguing about macro definitions, not notation.

view this post on Zulip Mike Shulman (Mar 17 2022 at 22:02):

I was using that to argue that no one is going to start being confused by the macro \R for the real numbers either.

view this post on Zulip Bruno Gavranović (Mar 22 2022 at 07:40):

Mike Shulman said:

Here's a trick in latex that does it for every letter automatically:

\makeatletter
\let\ea\expandafter
\def\foreachLetter#1#2#3{\foreachcount=#1
  \ea\loop\ea\ea\ea#3\@Alph\foreachcount
  \advance\foreachcount by 1
  \ifnum\foreachcount<#2\repeat}
\def\definecal#1{\ea\gdef\csname c#1\endcsname{\ensuremath{\mathcal{#1}}\xspace}}
\foreachLetter{1}{27}{\definecal}

One can argue about whether this is a better idea than writing a separate script in some other language to just spit out \newcommand{\cA}{\ensuremath{\mathcal{A}}\xspace} and its 25 friends...

So I finally tried this including this in my preamble, but it seems there's error here. I tried googling, but there's no useful results. I suppose I might need to include a particular package? (I already included xspace, but the error seems to happen before that line)

! Undefined control sequence.
\foreachLetter #1#2#3->\foreachcount
                                     =#1 \ea \loop \ea \ea \ea #3\@Alph \for...
l.17 \foreachLetter{1}{27}{\definecal}

view this post on Zulip Mike Shulman (Mar 22 2022 at 14:36):

Sorry, I omitted the \newcount\foreachcount before.

view this post on Zulip Bruno Gavranović (Mar 22 2022 at 15:25):

Ah, thanks. Took me a while to figure out that this was meant to be put before the code snippet you shared. Lots of LaTeX syntax is still a mystery to me...

view this post on Zulip Mike Shulman (Mar 22 2022 at 16:00):

This is actually plain TeX code, which has much greater potential to be mysterious. (-:

view this post on Zulip Mike Shulman (Mar 22 2022 at 16:02):

However, in reading about the knowledge package that @Ralph Sarkis recommended above, I encountered a link to the mathcommand package, which includes some easier syntax for doing this same thing; look for section 4 on \LoopCommand in its manual.

view this post on Zulip Jon Sterling (Mar 23 2022 at 07:31):

Another possibility for less mysterious (but still hard to learn) programming constructs is expl3. I've been using it a lot in my macros lately and it is very carefully thought out; it does not hide the bizarreness of the TeX model but attempts to tame it.

view this post on Zulip Bruno Gavranović (Mar 24 2022 at 16:10):

Jon Sterling said:

Another possibility for less mysterious (but still hard to learn) programming constructs is expl3. I've been using it a lot in my macros lately and it is very carefully thought out; it does not hide the bizarreness of the TeX model but attempts to tame it.

Ah, with all these improvements and functionalities one day I imagine someone will add types to LaTeX. Then the fun will begin...

view this post on Zulip John Baez (Mar 25 2022 at 20:31):

Typography will finally live up to its name.

view this post on Zulip Rich Hilliard (Mar 25 2022 at 23:33):

This is the first I've heard of expl3. I just looked at the expl3 README. Given that "the commands provided are not intended for use at the document level nor for use in describing design layouts in document class files" what sorts of things are folks using it for?

view this post on Zulip Jon Sterling (Mar 26 2022 at 07:57):

Rich Hilliard said:

This is the first I've heard of expl3. I just looked at the expl3 README. Given that "the commands provided are not intended for use at the document level nor for use in describing design layouts in document class files" what sorts of things are folks using it for?

It is intended to be used for programming macros (e.g. packages, classes, etc.), and that is what folks are using it for.

view this post on Zulip Jon Sterling (Mar 26 2022 at 07:57):

For instance, I used it to create a LaTeX package that reproduces old-school French-mathematics-style paragraph numbering: https://github.com/jonsterling/latex-dieudonne/blob/main/dieudonne.sty.

view this post on Zulip Rich Hilliard (Mar 26 2022 at 14:27):

Ah, I get it. Thanks!