Is there maximum number of characters of the figure title latex interpreter string?

Dear all,
I would like to write a multiline title using the latex interpreter.
I understand there is a limit of 1200 characters (minus roughly 10 characters for each line breaking).
I tried the following code but the interpreter fails.
title({[sprintf('$\\psi$ = %.0f$^\\circ$, $\\theta$ = %.0f$^\\circ$', rotationAngle,rad2deg(thetaIncidence)) newline ...
sprintf('$n_{Exp}$=%.2E, $vc_{Exp}$=%.2E', beta(1), beta(2)) sprintf('$\\sigma_n$=%.2E, $\\sigma_v_c$=%.2E', errBeta(1), errBeta(2))]},'Interpreter','latex')
Any idea?
Many thanks in advance

2 Comments

Simplify, simplify, simplify!!!! Break you string up into smaller pieces, debug each part to make sure of syntax...the LaTeX stuff is very fragile to proper syntax and very difficult to read easily. That there's no indication of which part fails doesn't help but is why simply have to work on the pieces from left to right, getting each working before going on to the next...
I tried to break the title in 3 pieces and each one works fine. The problem is when I put together the pieces.

Sign in to comment.

 Accepted Answer

Painful but manageable ;)
first = sprintf('$$\\psi = %.0f^{\\circ}$$', rotationAngle);
second = sprintf('$$\\theta = %.0f^{\\circ}$$', rad2deg(thetaIncidence));
third = sprintf('$$n_{Exp} = %.2E$$', beta(1) );
fourth = sprintf('$$vc_{Exp} = %.2E$$', beta(2));
fifth = sprintf('$$\\sigma_n = %.2E$$', errBeta(1));
sixth = sprintf('$$\\sigma_{v_{c}} = %.2E$$', errBeta(2));
title({first, second,third,fourth,fifth,sixth},'Interpreter','latex')

8 Comments

Precisely the more readable, at least have a chance to debug route suggested.
Also, this uses the "$$" quoting of the LaTeX "display mode" instead of single "$" of "inline mode". I've never seen an explanation of what the difference is; all the doc for LaTeX is essentially incomprehensible that I've ever been able to find. The entire section in the MATLAB tidbit as an adjunct to TEXT() consists of
"Use dollar symbols around the text, for example, use '$\int_1^{20} x^2 dx$' for inline mode or '$$\int_1^{20} x^2 dx$$' for display mode."
Most helpful, indeed -- not.
Yes dpb, I had to come up with the two dollar signs usually it’s used for math mode displaying equations.
"...the two dollar signs usually it’s used for math mode displaying equations"
Yeah, but the example shows the same formula written either way...with no explanation of what the difference is or why need two modes instead of one or even more frustrating, why to use one over the other.
The only way I've ever found is to just keep at it with trial and error and see what does/doesn't work. I've essentially written-off LaTeX as not being worth fooling with.
Ah neither have I understood that. So I do follow the trial and error , but the pain is real though :(.
But when I work in LaTeX environment single dollar signs are used for entering equations and double dollar sign are used to enter equations inside a text [text + equation combined] but like I said in this particular scenario it’s unclear to me like I said before, yet remains a mystery.
"Also, this uses the "$$" quoting of the LaTeX "display mode" instead of single "$" of "inline mode". I've never seen an explanation of what the difference is"
In scientific texts equations are either displayed on their own line (usually numbered on the RHS margin), e.g.
or they are simply printed inline with the text, e.g. . In both TeX and LaTeX these are called "display" and "inline" respectively.
Note that $ and $$ are actually TeX commands, not LaTeX commands, so the correct documentation for them is contained in the TeXbook itself. LaTeX has its own commands which are recommended:
  • \( and \).for inline math
  • \[ and \] for display math
Sadly in the usual manner of the internet there are plenty of sub-standard tutorials, blogs, and threads which mix up TeX and LaTeX. See also:
I have a difficult time finding documentation for TeX itself that is not LaTeX; even the documents I find that say they are talking about TeX specifically tend to be contaminated by LaTeX constructs.

Sign in to comment.

More Answers (1)

First, you must pass a char() string, not cellstr. You've got too many $ signs for pieces, but a start at what outlined above using
tstr=[sprintf('$\\psi = %.0f^\\circ$', rotationAngle)];
title(tstr)
does work...just keep adding pieces one at a time.

2 Comments

Dear dpb, I tried each one of the sprint strings (and the first two together) and they work fine alone. I tried char() and I still get the same wrong text.
Now I tried
text= [sprintf('$\\psi$ = %.0f$^\\circ$, $\\theta$ = %.0f$^\\circ$', rotationAngle,rad2deg(thetaIncidence)) newline ...
sprintf('$n_{Exp}$=%.2E, $vc_{Exp}$=%.2E', beta(1), beta(2)) sprintf('$\\sigma_n$=%.2E, $\\sigma_v_c$=%.2E', errBeta(1), errBeta(2))];
title(text,'Interpreter','latex')
and it still does not work fine, but I do not get anymore the warning on the interpreter.
As said, just piece together pieces one at a time. If you break somewhere along the line, that's the portion with a syntax error to fix (or you're trying to do something the MATLAB LaTeX implementation doesn't support).

Sign in to comment.

Categories

Find more on Scripts 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!