How do I obtain bold formatted mathematical expressions in MATLAB using LaTeX?

조회 수: 398 (최근 30일)
I want to place mathematical expressions in bold format on my plot. I have tried to use the {\bf} and {\textbf} declarations, but I receive an error and the expression does not get displayed. I am using the following commands to obtain the bold mathematical expressions:
text('position',[0.5 0.5],'Interpreter','latex','String','$\bf{\alpha}$')
This gives me the following error:
Warning: Unable to interpret TeX string. Undefined control sequence.
The following command uses {\textbf} instead of {\bf}
text('position',[0.5 0.5],'Interpreter','latex','String','$\textbf{\alpha}$')
but this results in the following error:
Warning: Unable to interpret TeX string. Missing $ inserted.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
The problem with the above two statements is that they are trying to mix Text mode and Math mode in LaTeX. One way to obtain bold fonts in Math mode is to use the {\boldmath} declaration. The following statement demonstrates the use of{ \boldmath}:
text('position',[0.5 0.5],'Interpreter','latex','String','{\boldmath$\alpha$}')
It is important to note that these commands should not be used in math mode. Thus, a complicated mathematical expression, where only certain symbols are desired in bold font, may be obtained by entering and exiting Math mode as required. Following is an example:
text('position',[0.5 0.5], 'Interpreter','latex','String','$\|${\boldmath${\alpha}$}$\|$');
  댓글 수: 1
Sim
Sim 2023년 12월 28일
편집: Sim 2023년 12월 28일
How to add a variable within "text", when using "boldmath"?
plot(1:10,1:10)
alpha = 3;
text(5,5,sprintf('{\\boldmath$\\alpha=%d$}',alpha),'Interpreter','latex','FontSize',20)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Daniel Frisch
Daniel Frisch 2021년 4월 30일
편집: MathWorks Support Team 2023년 1월 6일
With the LaTeX command
\mbox{}
you can also mix bold and non-bold symbols in one single equation:
text('position',[0.5 0.5],'Interpreter','latex','String','$\sqrt{ a \cdot \mbox{\boldmath $b$} }$')
Alternatively, you can use
\emph{\textbf x}
to achieve this:
text('position',[0.5 0.5],'Interpreter','latex','String','$\sqrt{ a \cdot \textbf{\emph b} }$')

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

제품


릴리스

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by