Using LaTeX packages in MATLAB Plots

26 次查看(过去 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 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by