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.
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...)
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...
Note the \ensuremath
and \xspace
, which lets you write things like
Let \cC be a category
without needing dollarsigns.
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).
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 (a symbol I have a lot of fondness for), not some other things I've seen people use, like \Real.
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. (-:
Switch it with the space bar. :stuck_out_tongue_wink:
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...
Mike Shulman said:
Note the
\ensuremath
and\xspace
, which lets you write things likeLet \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?
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?
I've never had any problems with ensuremath
.
Bruno Gavranovic said:
Does this mean that the prefix
c
in\cC
in your latex trick above doesn't refer tomathCal
, 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.
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.
Ralph Sarkis said:
If I can suggest one package, I highly recommend the wonderful knowledge package,
That package looks amazing! Thanks for the tip.
I semantically-macro everything, and when I don't I usually regret it.
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.
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.
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.
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.
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
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 would argue that f : \R \to \R
is more legible than f : \realNumbers \to \realNumbers
.
I was actually thinking that to many mathematicians, the distinction being made for in particular must be strange, because means the real numbers as much as the words "the real numbers" do.
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".
Although there are other uses of in the literature, e.g. Berger-Moerdijk use it to denote a Reedy category.
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.
This isn't literally true right? off the top of my head there's \SS
and probably \A
and \O
Mike Shulman said:
I would argue that
f : \R \to \R
is more legible thanf : \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.
I'd argue that after a while, any macro becomes descriptive. E.g.: \R
and 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).
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.
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.
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 likef \colon \R \to \R
. For readability I use\maps
to mean\colon
, sincef \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 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.
Knuth? But I agree with him: I don't like the equally wide spaces in , I like .
I like the equally wide spaces in something like .
But I'm obviously not a typist (= type theorist). I have never knowingly written a paper that says to mean " is of type ".
But when you write , it means " is of type ."
Mike Shulman said:
I would argue that
f : \R \to \R
is more legible thanf : \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.
Mike Shulman said:
But when you write , it means " is of type ."
Yeah, I get it. That's one way to read it, but I never write as the name of a type, so I don't think the sentence " is of type " when I see . Sorry, I'm one of the old-fashioned guys who will be left in the dustbin of history.
More importantly:
I just accidentally noticed that here on Zulip $$\R$$
produces this: .
Is \R
a built-in LaTeX macro for the real numbers? If so, I didn't know that.
I don't think so. At least, I've added that macro to the preamble of just about every paper I've ever written!
So maybe someone did it on Zulip.
KaTeX appears to render \R
as (I'm not sure for what reason), which is why Zulip does too.
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: )
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
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.
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.
I don't think anyone is going to stop using the notation for the real numbers.
Yes, :
is designed to have big equal-sized spaces on both sides:
\colon
is designed to be asymmetrical, with less space at left:
Mike Shulman said:
I don't think anyone is going to stop using the notation 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.
I was using that to argue that no one is going to start being confused by the macro \R
for the real numbers either.
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}
Sorry, I omitted the \newcount\foreachcount
before.
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...
This is actually plain TeX code, which has much greater potential to be mysterious. (-:
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.
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.
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...
Typography will finally live up to its name.
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?
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.
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.
Ah, I get it. Thanks!