Hi Antoine,
Le 28/08/2016 09:46, Antoine Monmayrant a écrit :
Le Samedi, Août 27, 2016 19:24 CEST, philippe <rouxph...@gmail.com> a écrit:
../..
Thanks Philippe, but nope, it does not work that easily.
It does for "\alpha", but my real use case is a bit more complicated and
calling titlepage directly is a mess.
I use titlepage(errormessage) where errormessage is a string array with a lot of starting
and trailing " " (white spaces).
I need to preserve these white spaces and use a monospace font to preserve the
relative alignment between the different lines in the array.
Doing this is a bit convolved when using titlepage alone:
- add some character at the begining of each line (to prevent titlepage from
stripping the white spaces),
- call titlepage,
- get a handle the the create textbox,
- change text justification (middle->lef centered)
- change font style (0 for monospace).
This is what I use now, but titlepage("$\verb| error message |$") would have
been more compact and elegant.
.
I definitely agree on the fact that xstring() (and xstringb(), called by
titlepage(),
and that are the guilty guys) always trimming all leading spaces is an
issue.
It should be the user's responsability to use stripblanks() whenever it
is required
before feeding xstring(), and that xstring() does not always do that in an
irreversible way (text stored in xstring.text is actually deblanked).
Presently, the text.alignment property can be either "left", "center"
and "right",
the default being "left".
IMO, a new *"as_is"* or *"none"* value should be added, and even become
the default.
For the time being, you may test and use the attached version of titlepage:
As soon as at least one of the strings has a leading space, the whole matrix
of strings is displayed "as is", in order to preserve any indentations
and so.
To do so, strings are displayed in LaTeX mode. Run
--> head_comments titlepage // to get details, or see the header in the
script.
This workaround has 2 drawbacks:
* lines are more compact (IMO too compact). I did not find any way to
tune this in supported LaTeX.
* The font style must be set when calling titlepage(). It can't be
changed with text.font_style,
and must be chosen when calling titlepage(). And only 3 fonts are
available.
But the text.font_foreground attribute works!
Example:
t = ["Here are indented nested lists"
" a) First point"
" * First item"
" * Second item"
" b) Another view"
" c) For a new titlepage()?"
]
clf
subplot(2,2,1)
titlepage(t)
xtitle("Default titlepage(t)")
subplot(2,2,2)
// exec() the new titlepage.sci
titlepage(t)
subplot(2,2,3)
titlepage([t ; "" ; t])
head_comments titlepage
subplot(2,2,4)
titlepage(t,0)
e = gce();
e.font_foreground = color("blue");
clear titlepage // comes back to the default titlepage()
*Results*:
This can be proposed as is to upgrade the present titlepage(),
even if it would be better to implement ASAP an "as_is" value for
xstring.alignment.
Cheers
Samuel
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 1989 - INRIA - Serge Steer
// Copyright (C) 2012 - 2016 - Scilab Enterprises
// Copyright (C) 2016 - Samuel GOUGEON
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function titlepage(varargin)
// titlepage([axes,] str [, ifont])
// axes: handle of an Axes or of a Figure or a Figure ID (optional)
// str: matrix of texts to be displayed
// ifont: ID of a loaded font (optional)
//
// If at least one component of str has a leading space, str is being
// displayed as is without trimming its spaces and centering strings.
// This allows displaying indented texts. LaTeX is then used, and
// available fonts are:
// ifont=0: Courrier ifont=2: Times Otherwise: Sans-Serif (Helvetica)
// In LaTeX indented mode, rows are more compact.
//
//titlepage(str) genere une page de titres graphiques contenant la ma-
//trice de chaines de caracteres str ecrite centree dans la page avec
//une taille de caractere maximale.
//!
a = varargin
old = gcf();
[lhs,rhs] = argn(0)
if rhs==0 | rhs>3 then
msg = gettext("%s: Wrong number of input argument(s): %d or %d expected.\n")
error(msprintf(msg, "titlepage", 1, 3))
end
if type(a(1))==10 then
str = a(1)
elseif (type(a(1))==[1 8])
win = double(a(1))
scf(win)
elseif type(a(1))==9
if a(1).type=="Figure"
scf(a(1))
elseif a(1).type=="Axes"
sca(a(1))
end
tmp = gcf()
win = tmp.figure_id
else
msg = gettext("%s: Argument #%d: Figure or Axes ID or Text(s) expected.\n")
error(msprintf(msg, "titlepage", 1))
end
a(1) = null()
// argin #2
if size(a)>0 then
if ~isdef("str","l")
if type(a(1))~=10 then
msg = gettext("%s: Argument #%d: Text(s) expected.\n")
error(msprintf(msg, "titlepage", 2))
else
str = a(1)
a(1) = null()
end
end
end
// argin #3
if size(a)>0
if ~or(type(a(1))==[1 8]) then
msg = gettext("%s: Argument #%d: Font ID expected.\n")
error(msprintf(msg, "titlepage", 3))
else
ifont = a(1)
end
end
// ----------------------------
plot2d([0,1],[0,1],[-1,-1],"022")
ax = gca()
ax.margins = [1 1 1 1]*0.07 // Gets more place for the text
ax.foreground = color("grey80") // Color of the frame
// If one of the strings has leading spaces, then all strings are displayed
// "as is" without trimming spaces neither leading nor trailing ones.
// This allows to display indented texts, as required
// We do that with LaTeX, since xstring() trims blanks
if or(part(str,1)==" ") then
fc = "\\sf"
if isdef("ifont", "l")
select ifont
case 0
fc = "\\tt "
case 2
fc = "\\rm "
end
end
str = strsubst(str, "\", "\backslash ") // Protects literal backslashes
k = grep(str, "/^\s*$/", "r")
str(k) = "\\ \\ " // Protects blank lines
str = "\mbox{"+str+"}"
// We must adjust the font scale. So, before, we measure it:
// 2 passes are required (for some unknown reason) to get the right scale:
wh = stringbox("$"+str+"$",0,0)
wh = wh([5 6])
wh = [wh(1) wh(2)]
xyfactor = min(1 ./ wh)
str0 = str
str = msprintf("$\\scalebox{%5.2f}{"+fc, xyfactor)+str0+"}$"
wh2 = stringbox(str,0,0)
wh2 = wh2([5 6])
wh2 = [wh2(1) wh2(2)]
xyfactor2 = min(0.95 ./ wh2)
// We end building the strings, and display them:
str = msprintf("$\\scalebox{%5.2f}{"+fc, xyfactor*xyfactor2)+str0+"}$"
x = (1-wh2(1)*xyfactor2)/2
y = (1-wh2(2)*xyfactor2)/2
xstring(x,y,str)
else
xstringb(0,0,str,1,1,"fill")
if isdef("ifont","l")
e = gce();
e.font_style = ifont
end
end
scf(old)
endfunction
_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users