Currently I would like to define whitespace that has this exact whitespace format
{ a, b, c }
{}
f : X -> Y
X:Y
(Notice the lack of space in {} and X:Y).
I would also like to style some of the greek characters with my own style, as well as the color of the punctuation characters.
Currently what I am doing is this:
\mylcurly a \mycomma b \mycomma c \myrcurly
But (besides being verbose) it breaks down in the case of { a, b, c } and {} because the whitespace is different for the two curly bracket pairs, so I end up having to do this:
\mylcurlya a \mycomma b \mycomma c \myrcurlya
\mylcurlyb \myrcurlyb
Same goes for the colon : in the initial example.
Essentially what I would like to do is twofold:
- Manage whitespace correctly.
- Manage custom colored characters correctly.
(It seems the LaTeX engine does all kinds of interesting stuff to the text behind the scenes, so wondering if I can somehow do the same).
I am wondering if my approach is the right one, or if there is a more LaTeX-y way of handling it. Perhaps there is a way to specify a style guide for the text in general, such as using pattern matching to define what sorts of things to style a certain way. For example, maybe there is a way to do this:
p > {
becomes
\mylcurly
A MWE is this:
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{color}
\newcommand{\myin}{\;\textcolor{blue}{\in}\;}
\newcommand{\mycolon}{\;\;\textcolor{blue}{:}\;\;}
\newcommand{\mycolonb}{\textcolor{blue}{:}}
\newcommand{\myrarrow}{\;\;\textcolor{blue}{\rightarrow}\;\;}
\newcommand{\mylarrow}{\;\;\textcolor{blue}{\leftarrow}\;\;}
\newcommand{\myeq}{\;\textcolor{blue}{=}\;}
\newcommand{\myand}{\;\textcolor{blue}{\land}\;}
\newcommand{\myor}{\;\textcolor{blue}{\lor}\;}
\newcommand{\mylcurly}{\;\textcolor{blue}{\{}\;}
\newcommand{\myrcurly}{\;\textcolor{blue}{\}}\;}
\newcommand{\mycomma}{\textcolor{blue}{,}\;}
\begin{document}
$\mylcurly a \mycomma b \mycomma c \myrcurly \mycomma \mylcurly \dots$
$\mylcurly\myrcurly$
$f \mycolon X \myrarrow Y$
$X \mycolon Y$
\end{document}
It shows the output like this:
{ a, b, c }, { ...
{ }
f : X -> Y
X : Y
when the output should be:
{ a, b, c }, { ...
{}
f : X -> Y
X:Y
I understand how to make it so the whitespace fits that pattern in this example. What I am not sure of is if this is the generally correct approach in "styling the text", or if there is a better way to do it that handles the edge cases of things like the lack of space in {} and same with X:Y in a better way (less ad hoc). In practice there are more examples of whitespace being off in different contexts, these are just a few simple ones I included in the MWE to simplify the question.
Update
Here is the original and the desired image if that's helpful. Also here is the source code that made the desired image.
$\mylcurly a \mycomma b \mycomma c \myrcurly\!\! \mycomma \mylcurly \dots$
$\mylcurly\!\!\!\myrcurly$
$f \mycolon X \myrarrow Y$
$X\!\!\! \mycolon\!\!\! Y$


\newcommand{\myin}{\;\textcolor{blue}{\in}\;}it would be much better to do\newcommand{\myin}{\mathrel{\textcolor{blue}{\in}}}and let tex autimatically space this as a mathrel (like\in) rather than having fixed;spacing. – David Carlisle Apr 21 '18 at 14:46\;but it should be avoided as far as possible as such spaces don't vanish automatically if for example the symbol is used at the start or end of a list. you can change the math class of symbols and you can change the size of the\medmuskipand\thickmuskipspaces that are added. But it is hard to suggest explicit settings in this generality. – David Carlisle Apr 21 '18 at 14:52\mathord,\mathbin,\mathrel, etc. – barbara beeton Apr 23 '18 at 00:06{}, have you considered defining\myemptybraces? – Davislor Apr 23 '18 at 06:08\mycolonto behave differently the two times you use it. I notice that there is an unused\mycolonb, however. Was one of them supposed to be that? – Davislor Apr 23 '18 at 06:11{ a, b, c }and{}you want without adding spaces manually by writing the first expression as{ \mathop{a,} \mathop{b,} \mathop{c,} }. – Davislor Apr 23 '18 at 06:34\mathrel, followed by\mathbin, and if you want very tight spacing, you could go to\mathord. Note that you can change the spacing between two different math classes in LuaTeX. – Davislor Apr 23 '18 at 06:36