Text and latex interpreter in xlabel

  • Context: LaTeX 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Latex Text
Click For Summary

Discussion Overview

The discussion revolves around how to format labels in MATLAB plots, specifically using LaTeX for the xlabel function. Participants explore different methods to achieve the desired text formatting, including superscripts and units.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant asks how to format the xlabel to include both a variable and units in LaTeX.
  • Another participant provides a solution using the xlabel function with LaTeX syntax.
  • A third participant shares a personal experience with rendering text in Java, mentioning the use of HTML tags for text formatting.
  • Additional solutions are offered, including variations of the xlabel command with different syntax options introduced in recent MATLAB versions.

Areas of Agreement / Disagreement

Participants present multiple approaches to the problem, indicating that there is no single agreed-upon method, but rather several valid solutions exist.

Contextual Notes

Some solutions depend on the version of MATLAB being used, particularly regarding the syntax introduced in R2021a.

member 428835
Hi PF!

I'm going insane here. How can I have the following in xlabel: ##Q \text{ (mm\sup 3/s)}##?
 
Physics news on Phys.org
Answer is here:
Code:
xlabel(['$Q$', ' (mm \textsuperscript{3}/s)'],'Interpreter','latex')
 
Nice, thanks for sharing.

Smetimes these kinds of display issues with text drive one insane. I once had to render some funky labels in Java and discovered that display text could in fact be a string of html tags to resize, colorize, fontify (a made up word to mean change the font to a more desireable one) the text. It really made my day too.
 
  • Like
Likes   Reactions: member 428835
joshmccraney said:
Answer is here:
Or,
[CODE lang="matlab" title="Till R2020b"]xlabel('$Q~\left( \mathrm{mm}^3/\mathrm{s} \right)$', 'Interpreter', 'latex')[/CODE]
Or, using the new Name=Value syntax introduced in R2021a,
[CODE lang="matlab" title="R2021a and later"]xlabel('$Q~\left( \mathrm{mm}^3/\mathrm{s} \right)$', Interpreter='latex')[/CODE]
 
  • Like
Likes   Reactions: member 428835 and jedishrfu

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K