Keep underscore symbol using latex as interpreter

91 ビュー (過去 30 日間)
Holden
Holden 2024 年 5 月 16 日
コメント済み: Holden 2025 年 1 月 23 日 19:53
Hello All,
I am trying to have one of the entries for my legend (which I like to have latex interpreter for) be the string to the data set I am analyzing (see image). And thus, I want to keep the underscore symbol as is (instead of making what follows a subscript) but still keep the latex as interpreter. I know that making interpeter 'none' it will ignore the subscript, but I want to keep the _ symbol in the legend AND use latex interpreter.
I have not figured out a way to do this (in the attached image, latex doesn't understand the dataName variable so it prints in a different font from the rest of the legend). I want the fonts to match.
Hopefully this makes sense

採用された回答

Steven Lord
Steven Lord 2024 年 5 月 16 日
This text call uses _ to make x a subscript of a.
text(0.25, 0.25, "Text with $a_x$ and LaTeX interpreter", Interpreter = "latex")
This text call uses \_ to include a literal underscore.
text(0.25, 0.75, "Text with $a\_x$ and LaTeX interpreter", Interpreter = "latex")
You can use replace to perform the replacement if you are reading the string you want to use as the legend label from a file.
s = "Text with $a_x$ and LaTeX interpreter"
s = "Text with $a_x$ and LaTeX interpreter"
s2 = replace(s, "_", "\_")
s2 = "Text with $a\_x$ and LaTeX interpreter"
  4 件のコメント
Holden
Holden 2024 年 5 月 16 日
Do the fonts match perfectly? Maybe my eyes are just playing tricks but the first entry still seems just slightly different
Holden
Holden 2025 年 1 月 23 日 19:53
Just came back half a year later to find this post and remember your answer. Can't believe it's been 6 months already yikes. Thanks again!

サインインしてコメントする。

その他の回答 (1 件)

Sam Chak
Sam Chak 2024 年 5 月 16 日
plot(0, 0, 'o', 'markersize', 20), grid on
legend('{$03 \textunderscore$May$\textunderscore 2024 \textunderscore$NoHS$\textunderscore 09$}', 'Interpreter', 'LaTeX', 'fontsize', 16)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by