How to display bold text using a custom .OTF font?

Hi,

I am trying to bold some part of text in a table but none of the technique I found in documentation works…

In the following example, data contains some value I want in bold format.

#table(
  columns: (1fr, 1fr),
  align: left,
  table.cell([*#data:*]),
...

I read about using * * here Table Function – Typst Documentation
I read about using text weight here Text Function – Typst Documentation

But my text always appears without the bold format.
What am I doing wrong, please ?

Can you please show us the definition of data? Because the above is not enough to reproduce your issue:

#let data = [Foo]
#table(
  columns: (1fr, 1fr),
  align: left,
  [*#data:*],
)

image

I suspect something inside data is forcing non-bold text

It could also be a problem with your font. Please add which font you are using.

1 Like

Oh sorry. I was not thinking the data could be a problem itself…
data is a struct in rust that can be formatted like this :

#let data = {f1:"some data", f2: "some other data", ...}
#table(
  columns: (1fr, 1fr),
  align: left,
  [*#data.f1:*],
)

In my example, I try to use #data.f1 in bold.

And my font is : texgyrecursor-regular.ttf that I get from here : typst-as-lib/examples/fonts at main · Relacibo/typst-as-lib · GitHub

I find it very hard to try to help you without a MWE… Your code does not compile.

I’ve refactored to something that (perhaps?) you are trying to achieve…

#let data = (f1:"bold data", f2: "not bold data",)
#table(
  columns: (1fr, 1fr),
  align: left,
  [*#data.f1:*],   [#data.f2:],

)

Which leads to
image

In other words, this code works. Perhaps the font?

font seems fine as well, although it is rather thin:
image

Are you sure it isn’t bold? Can you maybe provide a screenshot?

I’ve downloaded your font as per the URL and put in my working directory with the following file:

// font-test.typ
#set text(font: "TeX Gyre Cursor")

#let data = (f1:"bold data", f2: "not bold data",)
#table(
  columns: (1fr, 1fr),
  align: left,
  [*#data.f1:*],   [#data.f2:],

)

Running:

$ typst compile font-test.typ --font-path . 

with Typst 0.13.1 (on Arch Linux BTW), I get:
image

Output of fc-query
$ fc-query texgyrecursor-regular.otf
Pattern has 28 elts (size 32)
	family: "TeX Gyre Cursor"(s)
	familylang: "en"(s)
	style: "Regular"(s)
	stylelang: "en"(s)
	fullname: "TeXGyreCursor-Regular"(s) "TeX Gyre Cursor"(s)
	fullnamelang: "en"(s) "en"(s)
	slant: 0(i)(s)
	weight: 80(f)(s)
	width: 100(f)(s)
	foundry: "URW "(s)
	file: "texgyrecursor-regular.otf"(s)
	index: 0(i)(s)
	outline: True(s)
	scalable: True(s)
	charset: 
        ...
	lang: aa|ab|ast|av|ay|ba|be|bg|bi|bin|br|bs|bua|ca|ce|ch|chm|co|cs|cv|cy|da|de|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gn|gv|ho|hr|hu|ia|ig|id|ie|ik|io|is|it|kaa|ki|kk|kum|kv|ky|la|lb|lez|lt|lv|mg|mh|mk|mo|mt|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ro|ru|sah|sel|sh|sk|sl|sma|smj|smn|so|sq|sr|ss|st|sv|sw|tg|tk|tl|tn|tr|ts|tt|tyv|uk|uz|vo|vot|wa|wen|wo|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|lg|li|mn-mn|ms|na|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za|agr|ayc|bem|dsb|lij|mfe|mhr|miq|mjw|nhn|niu|sgs|szl|tpi|unm|wae|yuw(s)
	fontversion: 72286(i)(s)
	capability: "otlayout:DFLT otlayout:cyrl otlayout:latn"(s)
	fontformat: "CFF"(s)
	decorative: False(s)
	postscriptname: "TeXGyreCursor-Regular"(s)
	color: False(s)
	symbol: False(s)
	variable: False(s)
	fonthashint: False(s)
	order: 0(i)(s)
	namedinstance: False(s)
	fontwrapper: "SFNT"(s)

In my own humble opinion, it is a font problem.

Sorry for my entry data. In fact, I combine typst with rust.
I am a beginner using Typst and I make mistake about the type for “typst only use” with my “struct in rust” in my example. It is also why I need to create a example and I do not expose all my code.

Thank you very much to all of you. I will pay attention to police now.

1 Like

Just for follow-up…

I’ve added the texgyrecursor-bold.otf file from CTAN: /tex-archive/fonts/tex-gyre/opentype in my working directory. With the same code as my previous post, and the two font files, I get the desired text in bold.

image

So it was really a font question.
EDIT: And I’ve just found out that Typst does not support (yet) variable fonts.

Relates to Support variable fonts · Issue #185 · typst/typst · GitHub.

2 Likes