15

I would like a symbol that is identical to \le but where the "or equal" line (the line under the <) is green to emphasize to the reader the (or equal) part. That is, I want the new code to be identical in size and location, but just different in color.

I will only use this colored analog one time in my document so I prefer to enter it directly, rather than store it in a macro.

I used the following code in the hopes of getting something I could inject color into:

\documentclass{article}
\begin{document}
$3 \show\le 5$
\end{document}

This showed me the following useful output:

\le=\mathchar"3214.

From what I understand (Is there a numbered list of characters that \mathchar uses?), this means the \le is essentially its own character defined by the math font that's used. Thus, I wasn't sure how to inject color.

I don't think it would be hard to just draw a custom < with a line under it, but I'm hoping for something identical---other than color---to \le.

3
  • The "character number" is almost certainly the Unicode ID (I didn't check), so it's a single, indivisible character. There is no Unicode character that is separable in the manner you describe, and there isn't likely to be, so the most promising method is to create a composite, as you suggest. Please keep the result vertically centered on the math axis. Oct 22, 2023 at 19:53
  • @barbarabeeton it's not unicode, this is computer modern, but it is a single character Oct 22, 2023 at 20:23
  • @DavidCarlisle -- Oops! Thanks. The recommendation on alignment still holds though. Oct 23, 2023 at 2:40

3 Answers 3

6

Clip the top and bottom part, colorizing them separately (the upper part can be also colored), then overlap them with \ooalign.

\documentclass{article}
\usepackage{trimclip}
\usepackage{xcolor}

\makeatletter
\NewDocumentCommand{\cle}{O{green!70}O{.}}{%
  % #1 = color of the line, #2 = color of <
  \mathrel{\mathpalette\cle@{{#1}{#2}}}%
}
\NewDocumentCommand{\cle@}{mm}{\cle@@#1#2}
\NewDocumentCommand{\cle@@}{mmm}{%
  \ooalign{%
    \clipbox{0 {0.03\height} 0 0}{%
      $\m@th#1\mathcolor{#3}{\le}$%
    }\cr
    \clipbox{0 0 0 {0.97\height}}{%
      $\m@th#1\mathcolor{#2}{\le}$%
    }\cr
  }%
}
\makeatother

\begin{document}

$a \le b \cle c \cle[red!80] d \cle[green!70][blue!50] e$

$\scriptstyle a \le b \cle c \cle[red!80] d \cle[green!70][blue!50] e$

$\scriptscriptstyle a \le b \cle c \cle[red!80] d \cle[green!70][blue!50] e$

\end{document}

enter image description here

3
  • Nice approach! In the bottom row of your image, I see a little bit of the bottom line's color creeping into the '<'. But this might have answered my question. I was going to ask "how do you know what coordinates to clip to?". Is it correct that they might need to be adjusted depending on the font?
    – scottkosty
    Oct 23, 2023 at 16:32
  • @scottkosty You have better eyes than I. :-) Fixed. Yes, the factor obviously depends on the font.
    – egreg
    Oct 23, 2023 at 16:51
  • Great, thank you!
    – scottkosty
    Oct 23, 2023 at 16:55
6

Building a symbol by stacking a < on top of a - and adjusting the heights yields something pretty similar to \le, and then it's easy to add color. Maybe the heights are not perfect, but it's close.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\newcommand*{\coloredle}{%
    \mathrel{%
        \ooalign{%
            \raisebox{1pt}{\(<\)}\cr%
            \raisebox{-3.7pt}{\color{green}\(-\)}\cr%
        }%
    }%
}
\begin{document}
\(x \le y\)

\(x \coloredle y\)
\end{document}
4

If you don't want to load any packages you can do the following

\documentclass{article}
\begin{document}
    $5 \mathrel{\phantom\le\pdfliteral{q 0 0 -10 10 re W n}\llap{$\le$}\pdfliteral{Q q 0 1 0 rg 0 -3 -10 3 re W n}\llap{$\le$}\pdfliteral{Q}} 3$
\end{document}

enter image description here

Note that this solution is not portable, and will depend on the engine/driver you are using.

If you are using XeLaTeX add to the preamble \def\pdfliteral#1{\special{pdf: literal #1}}, and for LuaLaTeX add \protected\def\pdfliteral{\pdfextension literal} (or use these primitives instead \pdfliteral)

2
  • Interesting. So the \phantom makes it the same size as \le. Thanks for this different type of solution.
    – scottkosty
    Oct 23, 2023 at 14:24
  • 1
    @scottkosty, yes, the phantom is needed because the material inside the literals should be of zero width, otherwise the pdf coordinate and TeX's will not be synchronized. The \mathrel is for the spacing (rel for relation atom).
    – Udi Fogiel
    Oct 23, 2023 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .