Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

latex

LaTeX form of symbolic expression

Syntax

Description

example

latex(S) returns the LaTeX form of the symbolic expression S.

Examples

LaTeX Form of Symbolic Expression

Find the LaTeX form of the symbolic expressions x^2 + 1/x and sin(pi*x) + alpha.

syms x phi
latex(x^2 + 1/x)
latex(sin(pi*x) + phi)
ans =
  1×17 char array
\frac{1}{x} + x^2

ans =
  1×41 char array
\mathrm{phi} + \sin\!\left(\pi\, x\right)

LaTeX Form of Symbolic Matrix

Find the LaTeX form of the symbolic matrix M.

syms x
M = [sym(1)/3 x; exp(x) x^2]
latexM = latex(M)
M =
[    1/3,   x]
[ exp(x), x^2]

latexM =
\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &...
 x^2 \end{array}\right)

Use LaTeX to Format Title, Axis Labels, and Ticks

For $x$ and $y$ from $-2\pi$ to $2\pi$, plot the 3-D surface $y\sin(x) - x\cos(y)$. Store the axes handle in a by using gca. Display the axes box by using a.Box and set the tick label interpreter to latex.

Create the x-axis ticks by spanning the x-axis limits at intervals of pi/2. Convert the axis limits to precise multiples of pi/2 using round and get the symbolic tick values in S. Display the ticks by setting the XTick property of a to S. Create the LaTeX labels for the x-axis by using arrayfun to apply latex to S and then concatenating $. Display the labels by assigning them to the XTickLabel property of a.

Repeat these steps for the y-axis. Set the x- and y-axes labels and the title using the latex interpreter.

syms x y
f = y.*sin(x)-x.*cos(y);
fsurf(f,[-2*pi 2*pi])
a = gca;
a.TickLabelInterpreter = 'latex';
a.Box = 'on';
a.BoxStyle = 'full';

S = sym(a.XLim(1):pi/2:a.XLim(2));
S = sym(round(vpa(S/pi*2))*pi/2);
a.XTick = double(S);
a.XTickLabel = strcat('$',arrayfun(@latex, S, 'UniformOutput', false),'$');

S = sym(a.YLim(1):pi/2:a.YLim(2));
S = sym(round(vpa(S/pi*2))*pi/2);
a.YTick = double(S);
a.YTickLabel = strcat('$',arrayfun(@latex, S, 'UniformOutput', false),'$');

xlabel('x','Interpreter','latex');
ylabel('y','Interpreter','latex');
zlabel('z','Interpreter','latex');
title(['$' latex(f) '$ for $x$ and $y$ in $[-2\pi,2\pi]$'],'Interpreter','latex')

Input Arguments

collapse all

Input, specified as a symbolic number, variable, vector, matrix, multidimensional array, function, or expression.

See Also

| | |

Introduced before R2006a

Was this topic helpful?