Using LaTeX packages in MATLAB Plots
26 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Yash
on 4 Oct 2024
Hi @Luke
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 Comment
Yash
on 4 Oct 2024
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')
getDoubleStruckLetter('R')
getDoubleStruckLetter('B')
I hope this helps you in working with blackboard bold letters.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!