*! version 1.5 09jul2014
help graphlog (SJ15-2: gr0064)

Title

graphlog -- Convert log files to PDF files with embedded figures

Syntax

graphlog using filename [,
gdirectory(string)
psize(a4|letter)
porientation(portrait|landscape)
msize(#)
fsize(10|11|12)
lspacing(#)
splitoutput
sepfigures
fwidth(#)
enumerate
color(string)
encoding(string)
keeptex
replace
openpdf]

Description

graphlog converts already existing log files (.txt, .log, or
.smcl format) to a PDF document. It will embed figures saved during
the logged session into the PDF document, as long as the graphs have been
saved in .png, .gph, or .pdf format.

Options

gdirectory(string) specifies the directory where the graphics files are
placed. This is helpful if graphlog cannot find your graph.

psize(a4|letter) determines the paper size of the PDF document.
The default is psize(a4).

porientation(portrait|landscape) determines the page orientation.
The default is porientation(portrait).

msize(#) specifies the margin size in inches. The default is
msize(0.5). The minimum value is 0.1, and the maximum value is
2.5.

fsize(10|11|12) determines the font size. The default is
fsize(11).

lspacing(#) specifies the line spacing used in the PDF document. The
default is lspacing(0.7)

splitoutput allows output from one command to be split over multiple
pages. Use this option to conserve paper. Normally, graphlog will
split output over multiple pages only if the block of output is too large to
fit on one page.

sepfigures forces graphlog to place embedded figures on separate
pages in landscape mode (regardless of the page orientation of the rest of the
PDF document). If not specified, figures will be embedded on the text pages.

fwidth(#) defines the width of the figures as a fraction of the maximum
text width (that is, as a fraction of the paper width minus the margins). The
default is fwidth(1).

enumerate adds a footer on each page reading "Page X of
Y".

color specifies the text color in the PDF. The default is color(black). For a (non-complete) list of available colors, go to https://en.wikibooks.org/wiki/LaTeX/Colors#The_68_standard_colors_known_to_dvips

encoding specifies the character encoding of the log file. The default is encoding(uft8) on Linux/Mac OS X and encoding(ansinew) on Windows. If graphlog doesn't understand your non-latin characters, try another character encoding as described on https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Input_encoding

keeptex saves a copy of the TeX file for manual editing.

replace allows overwriting an existing PDF or TeX file.

openpdf opens the PDF document upon completion. Available only for
Windows systems.

Dependencies

For the graphlog command to work, the system must have a LaTeX compiler
with pdflatex installed (free of charge). For Microsoft Windows, I
recommend using MiKTeX (http://miktex.org/download); for Mac OS X,
MacTeX (http://tug.org/mactex); and for Linux, TeX Live
(http://tug.org/texlive).

Help! graphlog cannot find my graphs.

Because Stata does not write full paths to saved files, sometimes
graphlog will not be able to find the exported graphs. There are two
ways around this: Either execute the command pwd at least once during
the logged session before the graph is saved, or specifically tell
graphlog which folder to look in by using the option
gdirectory(string).

Known issue with apostrophes and grave accents

graphlog may display the error messages
program error: matching close brace not found or too few quotes if
you try to convert a log file containing apostrophes (') or grave
accents (`). If you have written grave accents or apostrophes in the
comments of your do-file, you can solve the problem by simply deleting the
problematic characters and rerunning the do-file and graphlog. If you
are programming Stata using local macros or compound double quotes
(`""'), your code probably needs those characters to function properly.
In that case, do the following:

1. Break the lines containing apostrophes or grave accents using /// so
that they become short enough to fit one line in the final PDF.

2. Rerun the do-file and graphlog.

3. If the problem persists, increase the number of characters Stata writes to
the log file before creating a line break. Type set linesize
# (without the quotes), where # is the maximum number of characters
on each line.

4. Rerun the do-file and graphlog.

Known issue with Mac OS X and Linux

If you are using Mac OS X or Linux and graphlog fails no matter which
log file you try to convert, it may be because Stata cannot find the
pdflatex program used by graphlog. To fix this, run the command graphlog_unix_setup and follow the instructions displayed.

graphlog_unix_setup

Known issue with leading blanks in filenames and directories

graphlog generally supports paths and file names containing blanks, but not
leading blanks. Thats is, graphlog understands when a graph is stored as
"my example .pdf" or the directory is "C:/Random user/Documents ". But it
does not understand the filename " example.pdf" or the directory "C:/ RandomUser/Documents".

Example

Start logging, generate a table and a graph, stop logging, and
convert the log to PDF

. preserve

. capture log close

. log using examplelog.log, replace

. sysuse auto

. summarize length

. scatter trunk length

. graph export examplegraph.pdf, replace

. log close

. graphlog using examplelog.log, replace

. restore

(click to run)

Author

Martin Rune Hansen

Aarhus University Hospital

Aarhus, Denmark

mrha@mil.au.dk

Also see

Article: Stata Journal, volume 15, number 2: gr0064