4

I have:

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}[Ligatures=TeX]
\setmathfont{STIX Two Math}
\usepackage{amsmath}
% need a suitable redefinition of ‘\gg’

\begin{document}
$\gg$
\end{document}

with Lualatex but I want to redefine \gg to print a boldface g (such as \symbf{g}). I even asked ChatGPT but it could not find any solution which would work. Is there any? (of course I know that I could use a different command....)

1
  • @samcarter_is_at_topanswers.xyz - I’ve augmented the OP’s code snippet to create an MWE. Commented 17 hours ago

3 Answers 3

9

I'm convinced that it's unadvisable to modify substantially the meaning of an existing command. By default, \gg produces ≫ (“much greater than” symbol).

In any case, if you really want to make your document unportable, the redefinition has to be done at begin document, after unicode-math has done its work.

Note that loading fontspec and amsmath is redundant, and Ligatures=TeX is on by default.

% Source - https://tex.stackexchange.com/q/760255
% Posted by mvs, modified by community. See post 'Timeline' for change history
% Retrieved 2026-02-27, License - CC BY-SA 4.0

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}

\AtBeginDocument{%
  \NewCommandCopy\mg\gg
  \renewcommand{\gg}{\symbf{g}}%
}

\begin{document}

$\gg\mg x$

\end{document}

output

2
  • 1
    Thanks for the suggested improvements. The reason for which I like \gg to give me a boldface g is that I use \vv, \cc, \xx etc. as a shorthand for boldface letters of which I have many. It basically is a double hit on a keyboard and I find it very convenient. I didn't want to have an exception for g. I never had troubles with this, even when I sent my latex code to math journals. Maurizio. Commented yesterday
  • @mvs Note that also \aa, \ll, \ss and \tt are defined. Redefining \aa and \ss might be troublesome as they're part of the LaTeX Internal Character Representation (LICR). Commented 14 hours ago
4

OK, I adapted a similar solution found here.

\AtBeginDocument{%
    \let\mg\gg
    \renewcommand\gg{\symbf{g}}%
}

does the trick nicely. Surprised ChatGPT couldn't find it.

Disappointing.

Maurizio

1
  • 2
    Please don't use \let with LaTeX (because \let cannot handle, i.e., protected commands correctly and it does not prevent you from unrecognized overwriting of an existing command). Instead use \NewCommandCopy (or if intended \RenewCommandCopy or \DeclareCommandCopy) as shown by @egreg. Commented 23 hours ago
4

In a comment below @egreg's answer, the OP wrote

The reason for which I like \gg to give me a boldface g is that I use \vv, \cc, \xx etc. as a shorthand for boldface letters of which I have many.

Rather than having to keep track of a plethora of two-letter macro names -- some of which will, sooner or later, interfere with existing macro names (such as \gg) -- that all accomplish the same thing, I suggest you create a single, specialized macro called, say, \bb, which bold-faces its argument. In a way, \bb is a shortcut to \symbf. Of course, it's up to you if you prefer writing \bb g or \bb{g}.

enter image description here

An advantage of using a single macro (\bb) instead of \vv, \cc, \xx, etc is that if you -- or the journal you're submitting a paper to -- decide that you'd like to generate bold-italic rather than bold-upright symbols, all you'll have to do is to change \newcommand\bb[1]{\symbf{#1}} to \newcommand\bb[1]{\symbfit{#1}}.

% !TEX TS-program = lualatex
\documentclass{article} % or some other suitable document class
\usepackage{unicode-math} % 'unicode-math' loads 'amsmath' and 'fontspec' automatically
\setmainfont{STIX Two Text} % 'Ligatures=TeX' is enabled by default
\setmathfont{STIX Two Math}
\newcommand\bb[1]{\symbf{#1}} % handy shortcut macro

\begin{document}
$\bb g \gg g$
\end{document}
3
  • 3
    I understand and I see the advantages. However, to be true, I learned about the double stroke option in some Latex forum many years ago and it seemed nice. Indeed I have many macros but in a sense they are all the same: hit a key twice, as on old typewriters when you wanted to have a pseudo bold. There is a logic. It is true that I get conflicts to solve, and that if I need to make a change I have to go through a bunch of corrections. I think that the source is more readable with my system, though. Maybe I'll change, I don't know. Anyway thanks for the great support by you guys. Commented yesterday
  • I just add that ChatGPT couldn't find a solution even after a very long dialogue I had with it. At the end it told me that "it is impossibile" (to redefine \gg in unicode-math). I was surprised because on this topic I assumed ChatGPT to be very strong. Not so. Here I found the solution in minutes. Commented yesterday
  • @mvs - You're welcome. FWIW, I'm not at all surprised to read that ChatGPT wasn't able to generate a workable solution to your LaTeX programming problem. Commented 18 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.