Hello,
Some time ago I used a function prettify by Pierre Vuillemin which enhances some features of plots. It seems to change the initial font_style of the plot element, but I can’t find it in the code. In my plot before “prettifing” I have italic Times New Roman font, but after that it changes to normal font.
Here’s the code which was shared by the Author in the Scilab users mailing list. Can you see here any line which can influence the font_style?
function prettify(e,options)
// Attempts to make a handle (e.g. a figure) pretty for articles.
//
// Syntax
// prettify(h)
// prettify(h, opt)
//
// Parameters
// h : the thing to prettify (handle), e.g. a figure handle
// opt : the options (structure)
//
// Description
// Given a handle, this routines attempts:
// - to transform the text it finds in latex,
// - to increase the font sizes,
// - to increase the thickness of lines.
//
// Default values (of thickness, font sizes, etc.) can be modified by giving
// a structure containing the options to modify.
// The available options are:
// - title_font_size (4),
// - labels_font_size (3),
// - thicks_font_size (2),
// - leg_font_size (3),
// - line_thickness (2).
// - xstring_font_size (2)
// - num_format ('')
//
// Example
// n = 1000;
// x = linspace(0,2*%pi,n);
// plot(x,sin(x),x,cos(x))
// h = gcf()
// title('Figure of $f_1(x)$ and $f_2(x)$')
// xlabel('$x$ (rad)')
// ylabel('$y$')
// legend('$f_1(x) = sin(x)$','$f_2(x) = cos(x)$')
// opt.line_thickness = 3
// opt.labels_font_size = 4
// prettify(h, opt)
//
// Options handling .........................................................
if argn(2) < 2 then
options = struct()
end
default_options = struct('title_font_size' , 4,...
'labels_font_size' , 3,...
'thicks_font_size' , 2,...
'num_format' , '',...
'leg_font_size' , 3,...
'line_thickness' , 2,...
'xstring_font_size' , 2)
// Assignation of default options
if ~and(isdef(fieldnames(default_options))) then
options = fill_options(options, default_options)
extract_fields(options)
end
// Switch case on the type of handle that has been provided .................
select convstr(e.type,'l')
case 'figure'
prettify_fig(e)
case 'axes'
prettify_axes(e)
case 'polyline'
prettify_polyline(e)
case 'legend'
prettify_legend(e)
case 'compound'
prettify_compound(e)
case 'text'
prettify_text(e)
end
endfunction
function prettify_text(t)
t.font_size = xstring_font_size
endfunction
function prettify_fig(f)
f.anti_aliasing = '8x'
for i = 1:length(f.children)
prettify(f.children(i))
end
endfunction
function prettify_axes(ax)
// Axis thicks
ax.font_size = thicks_font_size
ax.x_ticks.labels = latexify(ax.x_ticks.labels)
ax.y_ticks.labels = latexify(ax.y_ticks.labels)
ax.z_ticks.labels = latexify(ax.z_ticks.labels)
// Axis labels
labels_name = ['x_label','y_label','z_label']
for name = labels_name
label = ax(name)
label.font_size = labels_font_size
label.text = latexify(label.text)
end
// Title
T = ax.title
T.text = latexify(T.text)
T.font_size = title_font_size
//
for i = 1:length(ax.children)
prettify(ax.children(i))
end
endfunction
function prettify_polyline(po)
po.thickness = line_thickness
endfunction
function prettify_legend(leg)
leg.font_size = leg_font_size
leg.text = latexify(leg.text)
endfunction
function prettify_compound(co)
for i = 1:length(co.children)
prettify(co.children(i))
end
endfunction
function str = latexify(str)
if str == '' then
return
end
// 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 = T(i,:)
if isnum(T(i,:)) & ~isempty(num_format)
t = sprintf(num_format,evstr(t))
end
T(i,:) = '\text{'+t+'}'
end
out_str = ''
for i = 1:size(T,1)
out_str = out_str + T(i,:)
end
endfunction
function default = fill_options(opt, default)
opt_fields = fieldnames(opt)
def_fields = fieldnames(default)
// Displays a warning if some fields in opt are not available options
wrong_opt = setdiff(opt_fields, def_fields)
if ~isempty(wrong_opt) then
warn_msg = strcat(wrong_opt',''', ''')
disp('Warning: option(s) '''+warn_msg+''' are invalid. Discarding.')
possible_opt = strcat(def_fields',''', ''')
disp('Possible values are: '''+possible_opt+'''.')
end
// Replace default options with valid user-supplied options
for f = intersect(def_fields, opt_fields)
default(f) = opt(f)
end
endfunction
function extract_fields(stru)
varNames = fieldnames(stru)'
varValues = []
for v = varNames
varValues = [varValues,'stru.'+v+'']
end
exStr = '[' + strcat(varNames,',') + '] = resume(' + strcat(varValues,',')+');'
execstr(exStr)
endfunction
prettify(h, opt)
Regards,
Iza