clear clf() // The figure n = 100; x = linspace(0,2*%pi,n); y = sin(x); z = cos(x); plot(x,y,x,z) h = gcf(); title('Figure of $f_1(x)$ and $f_2(x)$') xlabel('$x$ (rad)') ylabel('$y$') legend('$f_1(x) = sin(x)$ (my favourite)','$f_2(x) = cos(x)$') // function prettyfy(f) // Your custom settings title_font_size = 4 labels_font_size = 3 thicks_font_size = 2 leg_font_size = 3 line_thickness = 2 // Some internal functions function str = latexify(str) // Adds $ at the beginning and the end of a matrix of strings for i = 1:size(str,1) str(i) = '$' + wrap_in_text(str(i)) + '$' end endfunction function out_str = wrap_in_text(str) // In a string containing normal text and latex expressions between $, this // routines wraps the text part inside \text{.} macros // '$f(x) = sin(x)$ is a nice function' --> 'f(x) = sin(x)\text{ is a nice function}' str = stripblanks(str) T = tokens(str, '$') if part(str,1) ~= '$' then start = 1 else start = 2 end for i = start:2:size(T,1) T(i,:) = '\text{'+T(i,:)+'}' end out_str = '' for i = 1:size(T,1) out_str = out_str + T(i,:) end endfunction // Axis thicks ax = f.children ax.font_size = thicks_font_size ax.x_ticks.labels = latexify(ax.x_ticks.labels) ax.y_ticks.labels = latexify(ax.y_ticks.labels) // Axis labels xl = ax.x_label xl.font_size = labels_font_size xl.text = latexify(xl.text) yl = ax.y_label yl.font_size = labels_font_size yl.text = latexify(yl.text) // Title T = ax.title T.text = latexify(T.text) T.font_size = title_font_size // Legend leg = ax.children(1) leg.font_size = leg_font_size leg.text = latexify(leg.text) for i = 1:length(leg.links) leg.links(i).thickness = line_thickness end endfunction prettyfy(h) xs2pdf(h,'~/test.pdf')