Azzera filtri
Azzera filtri

How to label the axes of a figure as Re and Im in the style of \mathfrak{Re} or \mathbb{Im} (from LaTeX \usepackage{})?

28 visualizzazioni (ultimi 30 giorni)
Ironically the Insert LaTeX functionality (provided for by the live editor) produces the desired result, e.g.: , but as far as I know this can not be utilized inside figures? Unfortunatley LaTeX packages which are not loaded in MATLAB by default are needed to use \mathfrak{}, \mathbb{} and \mathscr{}. I have done som digging, and from what I could gather it seems that the newer versions of MATLAB deals with LaTeX in a different manner than that of the earlier versions. Thus, the tex.m file cannot be edited to \usepackage{mathrsfs} and \usepackage{amssymb} as described here: https://stackoverflow.com/questions/12250919/how-do-you-use-the-latex-blackboard-font-in-matlab/12251619#12251619, and here https://tex.stackexchange.com/questions/98760/including-package-to-create-matlab-labels-using-latex/98803#98803. Is the \input and mwarticle.cls methods from the LaTeX Stack Exchange also obsolete? If not, how can they be used today? Are there any other methods which can be used to import/include LaTeX packages in MATLAB?
If not, when did this change, and can I download a MATLAB version before this was changed, such that I can follow the guide from StackOverflow, and include the packages I need?
Other possible solutions (?):
1. Are there any fonts that matches what I am looking for? Can I download and use amsfonts directly, and use it in \fontname?
listfonts % prints out all available fonts
title('\fontname{Courier} Re') % maybe one of the fonts looks like what \mathbb{Re} or \mathfrak{Re} produces?
2. \Re and \Im with 'tex' yields and + some trick I am not familiar with to obtain𝔢 and
xlabel('\Re', 'interpreter', 'tex') % Output is a nice R
xlabel('\Re e', 'interpreter', 'tex') % Output is a nice R, but the e looks horribly out of place
ylabel('\Im', 'interpreter', 'tex') % Output is a nice I
ylabel('\Im m', 'interpreter', 'tex') % Output is a nice I, the m does not look good
Are there any methods to get the second characters looking like the first?
3. Unicode?
Not sure as to how this would be implemented, and which unicodes to use for a nice looking Re and Im, which fits into a LaTeX generated pdf.
4. matlab2tikz?
  2 Commenti
Walter Roberson
Walter Roberson il 4 Nov 2022
Maybe one of
xlabel('$(A)\,\Re\textrm{e} (B)\,\Re\textsf{e} (C)\,\Re\texttt{e} (D)\,\Re\textbf{e} (E)\,\Re\textmd{e}$', 'interpreter', 'latex')
Warning: Error updating Text.

Font cmss10 is not supported.
The font warning is from the textsf version.
Walter Roberson
Walter Roberson il 4 Nov 2022
Unicode cannot be used with the LaTeX that Mathworks provides. Unicode can be used with interpreter 'tex' or 'none'
It looks like https://github.com/Happypig375/AMSFonts-Ttf-Otf contains amsfonts converted to TrueType (MATLAB needs TrueType)

Accedi per commentare.

Risposta accettata

Jørgen Myklebust
Jørgen Myklebust il 3 Gen 2023
Modificato: Jørgen Myklebust il 9 Feb 2023
I found a solution which gives me exactly what I want. Simply;
  1. Download the wanted font (as a .ttf file!)
  2. Install the font for all users (Windows PC: done by right clicking the .ttf file and installing on all users, I needed admin to do this)
  3. Make sure that the font shows up in the list when running listfonts in the Command Window. Take note of its name, since it is used to set the font in the figure. If ou have done the steps above and the font still does not show up, try to find a different font file and use that
  4. Make your figure
I downloaded this Fraktur BT font to get and like i wanted on my xlabel and ylabel.
Example of figure code (step 4), important commands at the bottom:
% Boilerplate________________________________________________
figure(1)
hold on
grid on
plot(rand(1,10), rand(1,10),'r-.*', 'LineWidth', 1.5);
title('\bf{Re og Im}', 'Interpreter', 'TeX')
xlabel('\bf{Re}', 'Interpreter', 'TeX')
ylabel('\bf{Im}', 'Interpreter', 'TeX')
legend('\bf{Complex Numbers}','Interpreter','TeX')
set(gca, 'TickLabelInterpreter', 'LaTeX');
hold off
%____________________________________________________________
% Here are the Important Commands! 'Fraktur BT' has to be changed with the
% font you want to use
set(get(gca, 'Title'), 'FontName', 'Fraktur BT', 'FontAngle', 'normal', 'FontWeight', 'normal', 'FontSize', 14);
set(get(gca, 'xlabel'), 'FontName', 'Fraktur BT', 'FontAngle', 'normal', 'FontWeight', 'normal', 'FontSize', 13);
set(get(gca, 'ylabel'), 'FontName', 'Fraktur BT', 'FontAngle', 'normal', 'FontWeight', 'normal', 'FontSize', 13);
set(get(gca, 'legend'), 'FontName', 'Fraktur BT', 'FontAngle', 'normal', 'FontWeight', 'normal', 'FontSize', 13);

Più risposte (1)

Santosh Fatale
Santosh Fatale il 10 Nov 2022
Hi Jorgen,
Following are answers to your questions:
plot(1:5, randi(10,1,5));
xlabel("\Ree \Imm", "Interpreter", "tex");
% No space between \Re and letter 'e' and same for \Im and letter 'm'

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by