New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matlab2tikz_acidtest exports not compilable .eps figures #370
Comments
A few days ago, I tried out a fix for exporting PDFs directly from MATLAB that I obtained from the MathWorks directly (I have an adapted version in my private repo if you'd want to experiment) There are some problems with this approach, though:
This doesn't give me much confidence in the other approach; since there also quite some other properties are modified. Moreover, it will certainly break for subplots. But this issue is certainly something we have to look into.
Attached: script that should give a tightly bounded PDF. %% (C) THE MATHWORKS (SERVICE REQUEST 01006478)
% Create the plot
figure(1)
plot(1:100)
% Create a copy, which we can modify
figure(2)
compCopy(1, 2)
% Do a normal pdf export
print -dpdf pdf_fullpage.pdf
% Set figure bounds to tight, to save ourselves from a lot of computations
% with margins etc.
ui.style.Bounds = 'tight';
hgexport(gcf, tempname, ui.style, 'applystyle', true);
% Get the image size and copy it into the paper size
image_pos = get(gcf, 'paperposition');
set(gcf, 'papersize', image_pos(3:4))
% Export a cropped figure
print -dpdf pdf_croppedpage.pdf
% Close figure 2
close(2)
%% This script call a function compCopy in order to copy a figure. The compCopy file reads:
% Copies content of figure source to figure dest
function compCopy(op, np)
ch = get(op, 'children');
if ~isempty(ch)
nh = copyobj(ch,np);
for k = 1:length(ch)
compCopy(ch(k),nh(k));
end
end
return |
@egeerardyn What's the licensing on this code? |
Christian Zietz from the epstopdf team found the issue:
He suggested to file a bug report with Miktex which I am gonna do. On the other hand I am wondering why So, the solution to the current issue would simply be to convert line endings in the generated .eps file according to the platform. |
@nschloe : I have no idea about the exact licensing terms. I think The MathWorks wouldn't mind if we post it here or in any project, as long as we're clear on the origin of the code. In the original fragment, there is no IANAL, but licensing should only be a potential problem if we ship a version with this code. In my personal (and private) branch, I rewrote part of the code, but the working is clearly identical. In the case we do get that approach working, I should inquire about licensing terms. |
@egeerardyn with respect to https://github.com/nschloe/matlab2tikz/issues/370#issuecomment-59932383 I do not understand why we cannot avoid the copy? We can save the old paper size and then set it back after the hgexport. Otherwise I have a fix that replaces on Win the |
@okomarov That's a good idea to test out (I will do that). You're probably right we can avoid it, it's just that I do not trust that |
I tried it out, most of it looks fine to me ( see ACID test ).
But I didn't find any bad crop location (unlike the original code) The main code I used for that: function printPDF(h, filename)
% Prints a figure to PDF from MATLAB
%
% NOTE: this implementation is based on code provided in a MATLAB
% service request (Case #01006478).
% tight figure bounds: less complicated calculations needed
ui.style.Bounds = 'tight';
hgexport(h, tempname, ui.style, 'applystyle', true);
%% capture old state
papersize = get(h, 'papersize');
%% correct positioning
image_pos = get(h, 'paperposition');
set(h, 'papersize', image_pos(3:4));
print(h, '-dpdf',filename,'-r150')
%% restore old state
set(h, 'papersize', papersize);
end |
TMW support confirms that the issue with Unix line endings on Win in Alternatively, https://github.com/ojwoodford/export_fig prints always to .eps first and then manually sets the bounding box with
|
Printing to PDF would reduce the complexity of the rest of the test suite, but it is not necessary per se. You're right that we can include your fix first (and close this issue) and fix the PDF thing later. I reckon you've tested your fix on your computer (as I don't have a Windows computer with R2014b installed)? |
The full acid.pdf is available here: https://www.dropbox.com/s/b7z4vtt695n7xsl/acid.pdf?dl=0 |
The figures exported to .eps do not compile with
epstopdf
and I get just a blank .pdf. I described the problem on http://tex.stackexchange.com/questions/208179/epstopdf-error-undefined-in-uagelevel and sent an email to the epstopdf team. It might be Matlab version dependent.However, there might be a workaround that sets the figure properties and exports a "cropped" .pdf directly, described on how to get rid of white margin in.html.
The text was updated successfully, but these errors were encountered: