I use syntax highlighting for Rust in raw blocks. I would like to use the colors of the highlighting elsewhere, like in math pseudocode or refering to a specific point in the code. I use the default color scheme. Where can I find the exact colors of the color scheme?
Example
I would like to replicate syntax highlighting in math notation. The function call of sqrt is supposed to have the same color as the blue text in the code, and specifying just “blue” as the color of the operator results in a slightly different color, which is undesirable.
```rust
fn sqrt(val: f32) -> f32 {
val.sqrt() }
```
Computing the magnitude of the vector $v$ which is $[2, 3, 6]$:
$
op(#{set text(color.blue); `sqrt`})(sum_(x in v) x^2) = 7
$
The simplest and most unflexible way is to color-pick the raw block (from a screenshot) and then replace color.blue with rgb("#XXXXXX") or create a variable with the color assigned.
#let blueish = rgb("#4C6AC6")
```rust
fn sqrt(val: f32) -> f32 {
val.sqrt() }
```
Computing the magnitude of the vector $v$ which is $[2, 3, 6]$:
$
op(#{set text(blueish); `sqrt`})(sum_(x in v) x^2) = 7
$
The issue with this solution is the lack of automatic updating when the raw block theme is changed. If you work with variables, this will make it easier, but might still require too much effort.
Thanks. That is a solution, and I imagined something like that, but I expected that someone would point me to a place in the source code where the color scheme is defined. Your solution would be probably indistinguishable, but having the same definitions would be better if the colors are not defined as RGB.
Another approach would be to use the built-in Syntax highlighting. First of all, inline code blocks also support syntax highlighting: ```rust x.sqrt()```
Sadly, writing ```rust sqrt``` won’t work because it’s not detected as a function. We can fix that by adding ( and then hiding it again:
show "(": none
```rust sqrt(```
As a complete example, we could define a function rawop like this:
#let rawop(name) = {
show "(": none
math.op(raw(lang: "rust", name + "("))
}
$
rawop("sqrt")(sum_(x in v) x^2) = 7
$