14

How can I get the output I get without unicode-math using unicode-math, preferably (not necessarily) using the same code (\boldmath)? I would like the solution to work with at least the XITS and Latin Modern fonts, both of which have no build-in bold math font..

edit: I can see attention is fading away. Of course it is not possible to make non-bold fonts 'truly bold', but the output Word produces when you make formulae bold is acceptable, and Cambria Math also doesn't have a bold font. You can even make XITS and Latin Modern bold in math just by pressing CTRL+B. I accept any answer that makes LaTeX behave like Word in this.

Without unicode-math

\documentclass{article}
\begin{document}
  This should be entirely bold: {\boldmath$O(\log n)$} \\
  This should not be bold: $O(\log n)$
\end{document}

I get nice-looking output:

Output without unicode-math.

With unicode-math, the code

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\begin{document}
This should be entirely bold: {\boldmath$O(\log n)$} \\
This should not be bold: $O(\log n)$
\end{document}

gives

With unicode-math 1.

I already tried a bunch of things, for example the following code.

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\setmathfont[range=\mathup/{greek,Greek,latin,Latin,num}]{XITS}
\setmathfont[range=\mathit/{greek,Greek,latin,Latin,num}]{XITS Italic}
\setmathfont[range=\mathbfup/{greek,Greek,latin,Latin,num}]{XITS Bold}
\setmathfont[range=\mathbfit/{greek,Greek,latin,Latin,num}]{XITS Bold Italic}
\begin{document}
This should be entirely bold: {\boldmath$O(\log n)$} \\
This should not be bold: $O(\log n)$
\end{document}

Which unfortunately gives me this:

With unicode-math 2.

Word output looks like this:

enter image description here.

David Carlisle
  • 757,742
Semafoor
  • 866
  • shouldn't this be ${\boldmath O(\log n)}$ instead? – pluton May 11 '12 at 14:44
  • 3
    There is no "XITS Math Bold" font (at the moment), so \boldmath doesn't do anything useful. – egreg May 11 '12 at 14:57
  • @pluton Nope, \boldmath should be activated outside of math mode. http://www.giss.nasa.gov/tools/latex/boldmath.html – Semafoor May 11 '12 at 14:57
  • @egreg But can't I use regular XITS Bold for the regular latin characters, greek characters and numbers inside of the equation? When I pust XITS Bold and XITS Bold Italic in the \mathup and \mathit range I get the output I want (but then everything is always bold). – Semafoor May 11 '12 at 15:00
  • My experiment with version=bold shows that there are big problems when the fonts used don't have the "Math" script. – egreg May 11 '12 at 15:41
  • @egreg I've been experimenting as well, to no avail :(. It is kind of sad that even something basic like boldness is not available for two popular fonts like XITS and Latin Modern. Is the only option then to move to yet another font?

    One very crappy option seems to be to use \setmathfont[version=bold,FakeBold=3.5]{XITS Math}, but that doesn't look good at all. edit: Also, it only works with XeLaTeX and not LuaLaTeX.

    – Semafoor May 11 '12 at 15:55
  • FakeBold doesn't work at all with LuaLaTeX – egreg May 11 '12 at 15:58
  • 1
    @Semafoor: The only OpenType math font with bold version is Lucida, even Cambria Math (the de-facto standard OT math font) does not have one. I plan to do one for XTIS, but no time for it now (unless someone wants to pay me to do it). On the other hand, patches are welcome :). – خالد حسني May 11 '12 at 17:46
  • @KhaledHosny: So there is no solution to my question? Also, if there is no 'elegant' solution, could there be a nice-looking workaround? It feels as if there should be one: Microsoft Word uses Cambria Math, and in Word it is possible to make equations bold. But then I suppose I don't know what I'm talking about :). – Semafoor May 11 '12 at 21:27
  • Why not use\mathbf etc? \boldmath is for all bold math (i.e. including non alphanumeric symbols), Word does not even support that. – خالد حسني May 12 '12 at 00:27
  • A solution without \boldmath that produces something like what Word produces would be great (bold alphanumeric symbols). That was actually what I was trying to achieve with my (non-working) 'solutions'. \mathbf makes cursive text stand up though... I'm definitely no expert: \boldmath was what I used before using unicode-math and custom fonts to make bold math. There may be other solutions. I must admit I didn't think this would be difficult for LaTeX experts to solve :). – Semafoor May 12 '12 at 02:21

2 Answers2

7

A "poor person's \boldmath can be obtained by

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\setmathfont[version=bold,FakeBold=3.5]{XITS Math}

\begin{document}
This should be entirely bold: {\boldmath$O(\log n)$} \\
This should not be bold: $O(\log n)$
\end{document}

I presume that this is how word processors fake bold for fonts not having a real one.

enter image description here

Note: choosing XITS "non math" for math symbols may have adverse effects.

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • 1
    At this point I'm quite desperate for an answer and this certainly works: I'll probably make this the accepted answer. As you also pointed out earlier, it only works in XeLaTeX.

    The output doesn't look as nice as the one word produces though (I added the Word output to the original input); this becomes more visible with 'more difficult' equations.

    – Semafoor May 12 '12 at 17:59
  • @Semafoor Experiment with the boldness factor. Of course the solution is either non using bold math or getting a font that has real bold math. – egreg May 12 '12 at 18:13
  • 1
    A problem is that, as KhaledHosny pointed out, there is currently only a single font (Lucida) that can be made bold, and it is not free. As someone who's not familiar with how LaTeX/XeLaTeX/... actually works under the hood, I'm surprised to 'lose' this functionality. For me, the best solution probably is reworking my document to no longer depend on unicode-math... But thanks for the effort you put in to solving my question! – Semafoor May 12 '12 at 18:18
  • @Semafoor: XITS Math now have a bold companion, it needs more work, but you can try it if you feel adventurous. Bug reports are welcomed. Next version of unicode-math will auto-load bold math fonts if avialable. – خالد حسني May 15 '12 at 21:44
  • @KhaledHosny Nice! Works and looks much better than fake bold. I'll try it out next time I have to write a LaTeX document :). – Semafoor May 19 '12 at 01:17
6

When using the package unicode-math, you will find the \bm and \boldsymbol don't work. You can nonetheless specify how you want it to deal with your bold math symbols using an option while loading it. \usepackage[bold-style=ISO]{unicode-math} will give the recommended italic bold math symbols for both greek and latin characters, while \usepackage[bold-style=TEX]{unicode-math} will give upright latin characters. This is explained in the unicode-math documentation.

A mwe:

\documentclass{article}
\usepackage[bold-style=ISO]{unicode-math}
%\usepackage[bold-style=TEX]{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\begin{document}
This is bold and italic $\mathbf{O(\log n)}+\mathbf{O(\lambda,\,\epsilon)}$ where it must :)
\end{document}
  • I've tested what you said. But I found that if we need bold math characters, we should use \symbf{} instead of \mathbf{}. We can read texdoc unicode-math 's sec3.1, paragraph 4. And how symbf{} behaves depends on the package option bold-style= – Syvshc Jan 09 '21 at 14:23