Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Creating HTML from SMCL log file including graphics - revised log2html.ado

From   "David Elliott" <>
Subject   Re: st: RE: Creating HTML from SMCL log file including graphics - revised log2html.ado
Date   Fri, 19 May 2006 09:54:11 -0300

1) The only way to guarantee reliable rendering in all browsers is to
use the Portable Network Graphics file format.  While IE will display
Windows Metafiles, Gecko browsers will not.  It is possible to add the
capability of picking up other filetypes by deducing the extension
from what follows the 'written in' portion of the export confirmation,
since as I have commented in (2) below, the extension is not included
in the confirmation message when the -graph export filename, as(png)-
form of the command is used.

2) You said: "True, but the file produced does not have an extension,
so adding one in the <img> tag will not help."

Actually, the .png extension is added to the file regardless of what
the confirmation message said - try it yourself, you'll see.
Personally, I think this is a deficiency in the graph export command i
it should state the filename and extension.

3) Creating reliable relative addressing is beyond me.  Handling
reference to an ./image/ subdirectory would not be too difficult but
the real problem arises because the graphic is saved to the pwd by
default which one doesn't necessarily know from the log itself and the
log could be saved to a different directory.  I believe it must be the
user's responsibility to have the log and html file and images in the
same directory.  I don't think one can be sufficiently adaptable
programmatically to handle all the relative path possibilities.  If
someone wants to try, hats off to them!

4) Thanks for the explanation on index(...) - I haven't used the
string functions extensively before and was unaware of strpos(...)'s
previous name.  Your code is more elegant would allow capture of a
filename with a space.  I would then have to work back to the slash to
extract the filename.

5) A gropts() argument is certainly possible, for example, to create a
style="display:block;margin:5px; border:2px outset #333; padding:5px"
display style for the images.  (alternatively, that could be added to
the CSS in the head)

Once again, thank you for you help and interest.


On 5/19/06, David Harrison <> wrote:
David Elliott wrote:

1) The restriction to only png is that, if this is going to be rendered
as HTML, this is the only bitmap file format that can be displayed on
all the browsers I tested.

A fair point. Some people may prefer another format, provided it renders
on their own browser.

2) If you examine the output from the following 4 -graph export-
commands you will see that the extension is not included when you use
the [,as(png)] argument: <snip>

True, but the file produced does not have an extension, so adding one in
the <img> tag will not help.

3) Ideally, one would have paths relative to the directory in which the
html log was written.  Unfortunately STATA's string handling functions
don't include drive|path|filename|extension aware functions like
JUSTDRIVE( ) | JUSTEXT( ) | JUSTFNAME( ) | JUSTSTEM( ) that would allow
parsing the various file locations and their relationships relative to
each other.  For ease of coding and possibility of moving the htmllog
and images to a different directory in the future, I believe they should
be in the same directory.  If you hard code the directories, moving the
files will break the links.  For Internet Explorer, a reference to
src="c:\web\test.png" will work, but in Gecko-based browsers like
Netscape|Firefox, it will fail.

Fair point- I was thinking that assuming the html log is going in my
working directory I may want to code, e.g. -graph export
images\fig1.png- and have the relative location picked up.

4) I am aware on the inability to include multiple word filenames.  As a
general rule, it is inadvisable to have space-separated filenames in web
addresses.  I could pick up the entire filename, or parse back to the
preceding '\' or '/' but it is harder than it looks.  I am unable to
find the index(...) function to which you refer although there is an
indexnot(...) function referenced under -help string_functions-

I agree that the filename itself is best not to have spaces, but there
is no reason why the path (which is being stripped off anyway) should
not. Either way, it would be better to make the code exit with an error
or do nothing at all if a space-separated name is encountered, rather
than substituting a link to a non-existent file. The command -index()-
was renamed -strpos()- in version 9, I used -index()- as the program has
the version set to 8.

5) Any suggestions as to what verbatim options you would want,
remembering that it would be applied to all images?  The <img> tag
doesn't have a lot of attributes.  While good coding practice would have
the height and width explicitly specified, this only really helps when
rendering complex designs since the layout engine is able to know the
dimensions of images before they have fully downloaded.  You have the
dimensions only if explicitly specified with the height(600)
width(800) arguments.

The options do not need to be specified. If you add, say, -gropts(str)-
in the syntax and then -`gropts'- inside the <img> tag, I can pass any
options I like to all the graphs when I create the html file.


This email has been scanned by the MessageLabs Email Security System.
For more information please visit

*   For searches and help try:

David Elliott

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index