Greek letter \xi issue in Matlab eps print out - matlab

When I plot a figure and type greek letter in the title, it looks like
However, when I save the figure as EPS output, the eps file looks like
It's obviously that the Greek letter \xi_p disappears.
Anyone who knows what happened and solutions, please give me a reply.
It would be much grateful.
Best regards,
mike

First I would like to thank KiW for the help.
I found a solution that works with my MATLAB 2014b.
Solution by specifying the interpreter directly in the code
We can set the interpreter-property directly to latex when calling xlabel or title as shamalaima pointed out in a comment:
xlabel('$\xi_{\textrm{p}}$','Interpreter','latex');
title('$\xi_{\textrm{p}}$','Interpreter','latex');
Solution using the property editor
Another way to do it is by using the property editor as follows:
After making the figure, click the white arrow and click the title (or label).
In the Property Editor, change the Interpreter to latex.
After this, choose the Axes. We can now find the title editor in the left bottom side. Just write the title as you do in latex.
Mine would be $\xi_{_\textrm{p}}=1e$-$4a_{_\textrm{ho}}$ in the font of Times New Roman.
It works now in my EPS output.

Using EPS Viewer the symbol is not lost. As you can see in the picture that works perfectly fine. I used:
plot(x,y)
title('\xi _{P}=1e-4a _{ho}')
So I assume it could be a problem of the program you use to open your .EPS file

I think that the best solution is to set the latex interpreter as default:
set(0,'defaulttextinterpreter','latex')
but of course it depends case by case.

Related

Is EPS image editable

I converted a matlab fig to eps, I need to add the grid to this figure which now I have in eps format. Is there any possibility. I know I can change the title or labels using ultraedit or similar programs but cant identify the relevant place for grid.
Yes, you simply need to read the PostScript program and then modify it to be suitable for your needs.
You will, however, probably need a working knowledge of the PostScript language in order to understand the program and succesfully modify it.

Saving figure to pdf prints # instead of tabs in titles

if I create a plot with some tabs in the titles and try saving that to a local pdf file (via print function), I get some hashtags instead of tabs in the pdf. This does not occur in the visible figure.
For example, I plotted the residuals of an approximant to the runge function on a grid:
plot(g, f(g) - runge(g));
title(sprintf('residuals,\t max_x(s-f) = %.3f', max(f(g)-runge(g))));
Then after some axes manipulation (grid, boxes, etc..) I execute
h = gcf;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(h,'data/runge_example.pdf','-dpdf','-r200')
close(h)
Is somebody aware of that behaviour or better able to found that as already solved than I am?
EDIT: Same behaviour with saveas and saving to eps. This does not happen with \n
EDIT2: I'm using Matlab Version R2017b (9.3.0.7...)
So, after a long discussion we figured out that we have no idea of how to use tabs in matlab titles in combination with latex mode.
To clarify: use math environments and escape tex directives, otherwise it will throw an error.
so
sprintf('residuals,\t $max_x(\\vert s-f\\vert) = %.3f$', max(f(g)-runge(g))));
will give you a nice string:
residuals, $max_x(\vert s-f\vert) = 0.264$
The problem is, that it really is a tab. And the matlab latex interpreter (don't know which one that uses, the system or an own) crashes on that. I copy-pasted that to a tex document and pdflatex ran fine on it (but not showing that much space unfortunately).
So, I came up with the following fix:
use the latex directive \quad or \qquad:
title(sprintf('residuals,\\quad $max_x(\\vert s-f\\vert) = %.3f$', max(abs(f(g)-runge(g)))));
This will give you more space than a normal space.
EDIT: For this to work you need the interpreter of matlab to be set to "latex" instead of the default "tex". Do this by changing the title to
title(title_string, 'Interpreter', 'latex')
or by setting (globally for that script)
set(groot, 'defaultTextInterpreter', 'latex')

How to include a script letter in matlab figure label

I want to include a script English letter, say \mathscr{T} in the Y-axis label in a Matlab figure. Is there an easy way to do this? Thank you.
Matlab's LaTeX interpreter doesn't seem to recognize \mathscr. But it accepts \mathcal:
ylabel('$\mathcal{T}$','Interpreter','LaTeX','Fontsize',12)

MATLAB: checkmark in MATLAB figure with LaTeX interpreter

In my figure I have a text annotation using the LaTeX interpreter, and it doesn't recognize \checkmark because MATLAB doesn't have the amsmath package.
Are there any ideas for a workaround? Perhaps I can have part of the text box interpreted with LaTeX, and part of it without? In that case I could use this solution.
it's not pretty, but might be good enough:
xlabel('$\surd$','interpreter','latex')
or look here for other things that look like a tick
http://detexify.kirelabs.org

How to print figure to clipboard by PRINT function with the quality identical to 'Edit-->Copy Figure' option?

Is there any way to print the figure to the clipboard so that the quality is identical to what the Edit-->Copy Figure option provides?
I used to save the figure to powerpoint file by using saveppt.m obtained from Matlab Central. It worked well until yesterday. I noticed that the stored image quality was somehow degraded. I tried to re-generate some ppt slides with exactly the same script and the same source data, but the new slides are simply of worse quality.
I investigated into this problem a little bit and discovered that when the figure is copied to clipboard by running print -dmeta, the image in the clipboard is already degraded, while if I use the Edit-->Copy Figure option in the figure window, I get the image as clear as the original image in the figure window.
Following is an example for your reference. I copied the image from a figure to the clipboard by two different methods, and paste it to Microsoft Paint program, and cut a piece of it to show below:
The image using print -dmeta:
The image using Edit-->Copy Figure:
If you compare the Xtick label '50', you may see that the image from Edit-->Copy Figure is smoother.
At the beginning I thought it was a problem of the resolution, but setting -rN to change the resolution does not seem to resolve my problem, at least not for N<=300.
Thank you for your help.
The short answer... Use the same function invoked in the callback for that menu item:
editmenufcn(gcf,'EditCopyFigure');
The longer answer... How exactly did I find this? You can look at my previous answer to a related question about reproducing what is done by a File menu option. The concept is the same, just for a different figure menu. For example, this will find the callback you want for the currently active figure window:
>> hCopyFigure = findall(gcf,'Label','Copy &Figure'); %# Handle for the "Copy
%# Figure" menu item
>> get(hCopyFigure,'Callback') %# Callback invoked when that item is selected
ans =
editmenufcn(gcbf,'EditCopyFigure')
The function EDITMENUFCN is another one of those sparsely documented functions, but looking through the code (by typing edit editmenufcn.m) shows that it either invokes Java (if you're on a Mac) or the undocumented function UIMENUFCN.
I think I found the answer myself. Using print -dmeta -painters to specify the renderer resolves my problem.
In File-->Preference-->Figure Copy Template-->Copy Option I noticed there are 3 options:
Metafile
Preserve information
Bitmap
I found that if I select 1, the Edit-->Copy Figure outputs the same image as print -dmeta. So I kind of confirmed the information I need is in the Preserve information option. A quick google search led me to the discussion about the potential difference of the applied renderer, and eventually I confirmed that using painters will print the image to the clipboard in the way I wanted.
The image in the question seems to be generated by the renderer zbuffer and painters, respectively. I still don't know why the default renderer of paint -dmeta changes, though.