\underline that is identical to normal underline

10 views
Skip to first unread message

Andrew Murdza

unread,
Oct 18, 2025, 4:48:56 PMOct 18
to MathJax Users
I want \underline{...} to make an underline under with text-decoration: underline 2px; text-underline-offset: 7px; and also to exactly match the currentColor, just like my .underline class.

So if I have <span class="red underline">Hi$\class{red}{\underline{\text{Hi}Hi}}$</span>, the underline would be at the same vertical position, the same color, and the same thickness for all three, regardless of the Zoom percentage.

How can this be done with MathJax?

Davide Cervone

unread,
Oct 19, 2025, 6:50:12 PMOct 19
to mathja...@googlegroups.com
Here is a macro that I think will do what you want.

\def\textUnderline#1{#1\llap{\style{padding-bottom: 7px; border-bottom: 2px solid}{\phantom{\smash{#1}}}}}

or

MathJax = {
  tex: {
    macros: {
      textUnderline: ['{#1\\llap{\\style{padding-bottom: 7px; border-bottom: 2px solid}{\\phantom{\\smash{#1}}}}}', 1],
    }
  }
};

For your example (substituting \textUnderline for \underline, though you could redefine \underline if you prefer) produces

PastedGraphic-1.png

Note, however, that if the math extends far below the baseline (which is often the case in mathematics, but perhaps not in what you are going to be using), then the underline will extend over it, as in

<span class="red underline">Hi$\textUnderline{\text{Hi}Hi{\color{blue}\Bigg(}}$</span>

produces

PastedGraphic-3.png

If you wanted to have the blue parenthesis be above the red underline, then use \rlap rather than \llap and move the #1 to the end of the macro instead.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mathjax-users/634cab6d-ae83-4657-a624-5106eb68adb9n%40googlegroups.com.

Andrew Murdza

unread,
Oct 19, 2025, 8:31:53 PMOct 19
to MathJax Users
I tested it and it works! You're right that I wouldn't have things extending below the math, but it is nice that I can still use the other underline if I do end up needing that. Thanks so much! I wished I had asked you much earlier because I spent hours with ChatGPT trying to do it with CSS and JS, when what I really needed was \\llap. 

Davide Cervone

unread,
Oct 20, 2025, 6:00:52 AMOct 20
to mathja...@googlegroups.com
Yes, ChatGPT is crap at this kind of thing.  It is not creative and can not produce an answer to something that hasn't already been done before, as it can only recombine the ideas that it has been trained on.  It doesn't understand any of it, and can't generate a new idea if it hasn't already seen at least teast the pieces that it needs to put together.  Don't waste your time with it, and think about things yourself instead.

Davide

Reply all
Reply to author
Forward
0 new messages