![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1797540/image.png)
Mixed LaTeX math and text in Matlab
조회 수: 19 (최근 30일)
이전 댓글 표시
How can I mix LaTeX text and math modes?
At the moment I have things like : '$\theta_{Co}$'. In a plot, It works and the subscript Co comes out in math style italics. Sweet.
I now want the subscript to print out as normal text.
In Overleaf - LaTeX IDE that I'm using - I can write \theta_{\text{Co}}$ and that comes out as i want -
When I try that in Matlab it prints out the string as the code \theta_{\text{Co}} . What can I do?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/506558/image.png)
Thanks, David
댓글 수: 0
답변 (1개)
Shlok
2024년 10월 23일
Hi David,
It seems you're trying to mix LaTeX text and math modes in MATLAB but aren't getting the desired output. To fix this, you can use the “\mathrm” command within the math mode.
This command renders text in an upright (roman) font within a math expression, ensuring that non-mathematical symbols are styled correctly.
Here is a sample code, which prints “$\theta_{Co}$” same as your desired output (
):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1797540/image.png)
figure;
% Plotting random data
plot(1:10, rand(1, 10));
title('$\theta$', 'Interpreter', 'latex');
xlabel('x');
ylabel('y');
% Add a text annotation with LaTeX formatting
text(5, 0.5, '$\theta_{\mathrm{Co}}$', 'Interpreter', 'latex');
You can refer to the following MathWorks Documentation link to learn more about using LaTeX in MATLAB:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!