Using LaTeX packages in MATLAB Plots

조회 수: 22 (최근 30일)
Luke
Luke 2018년 3월 5일
댓글: Yash 2024년 10월 4일
Hello,
I am trying to find out if there is a way to install LaTeX packages to use in MATLAB plots (e.g. x and y axes labels, titles, text annotation, etc.). In particular, I would like to use the blackboard bold font (\mathbb{}) in the amsmath package.
Similar questions include:
  • LaTeX Interpreter and Blackboard bold (\mathbb{}) for text ( link )
  • How do you use the LaTeX blackboard font in MATLAB? ( link )
  • Including package to create MATLAB labels using LaTeX ( link )
After probing into this, I quickly realized that this is much harder to do then I initially thought. (I am also a bit surprised that this isn't already supported.) It seems like in older versions of MATLAB it was possible to modify the tex.m file somehow to achieve the desired results; however, this is not possible as in the newer versions of MATLAB, I cannot edit the file at all (note: I am using version 2017b of MATLAB).
I am also looking to see if there is a solution native to MATLAB. Unless I have exhausted all other options, I do not wish to do something like export the figure to an eps file using psfrag and then add the fonts, or use matlab2tikz just for this.
Thanks so much!

답변 (1개)

Yash
Yash 2024년 10월 4일
If you want only a few characters, you can use the Unicode decimal code for them. For example, the Unicode decimal code for is 8477 and it can be used as follows:
mathbbR = char(8477)
I hope this helps!
  댓글 수: 1
Yash
Yash 2024년 10월 4일
I further checked and found that MATLAB supports only a few blackboard bold letters (C,H,N,P,Q,R,Z). I have came up with this script which might help:
function doubleStruck = getDoubleStruckLetter(normalLetter)
keyValuePairs = {'C', char(8450); 'H', char(8461); 'N', char(8469);
'P', char(8473); 'Q', char(8474); 'R', char(8477);
'Z', char(8484);};
% Create the map using the cell array
doubleStruckMap = containers.Map(keyValuePairs(:, 1), keyValuePairs(:, 2));
% Check if the input letter exists in the map
if isKey(doubleStruckMap, normalLetter)
doubleStruck = doubleStruckMap(normalLetter);
else
doubleStruck = 'Double-struck version not available for the given letter.';
end
end
Just add the following function as a separate script getDoubleStruckLetter.m in your working folder or MATLAB Path and call the function as follows:
getDoubleStruckLetter('C')
ans = 'ℂ'
getDoubleStruckLetter('R')
ans = 'ℝ'
getDoubleStruckLetter('B')
ans = 'Double-struck version not available for the given letter.'
I hope this helps you in working with blackboard bold letters.

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

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by