1\chapter{Gretl and \TeX}
2\label{chap:gretltex}
3
4
5\section{Introduction}
6\label{tex-intro}
7
8\TeX\ --- initially developed by Donald Knuth of Stanford University
9and since enhanced by hundreds of contributors around the world --- is
10the gold standard of scientific typesetting.  Gretl provides
11various hooks that enable you to preview and print econometric results
12using the \TeX\ engine, and to save output in a form suitable for
13further processing with \TeX.
14
15This chapter explains the finer points of gretl's \TeX-related
16functionality.  The next section describes the relevant menu items;
17section~\ref{tex-tune} discusses ways of fine-tuning \TeX\ output; and
18section~\ref{tex-install} gives some pointers on installing (and
19learning) \TeX\ if you do not already have it on your computer.  (Just
20to be clear: \TeX\ is not included with the gretl distribution;
21it is a separate package, including several programs and a large
22number of supporting files.)
23
24Before proceeding, however, it may be useful to set out briefly the
25stages of production of a final document using \TeX.  For the most
26part you don't have to worry about these details, since, in regard to
27previewing at any rate, gretl handles them for you.  But having
28some grasp of what is going on behind the scences will enable you to
29understand your options better.
30
31The first step is the creation of a plain text ``source'' file,
32containing the text or mathematics to be typset, interspersed with
33mark-up that defines how it should be formatted.  The second step is
34to run the source through a processing engine that does the actual
35formatting.  Typically this a program called \app{pdflatex} that
36generates PDF output.\footnote{Experts will be aware of something
37  called ``plain \TeX'', which is processed using the program
38  \app{tex}.  The great majority of \TeX\ users, however, use the
39  \LaTeX\ macros, initially developed by Leslie Lamport.  gretl does
40  not support plain \TeX.} (In times gone by it was a program called
41\app{latex} that generated so-called DVI (device-independent) output.)
42
43So gretl calls \app{pdflatex} to process the source file. On MS
44Windows and Mac OS X, gretl expects the operating system to find the
45default viewer for PDF output. On GNU/Linux you can specify your
46preferred PDF viewer via the menu item ``Tools, Preferences,
47General,'' under the ``Programs'' tab.
48
49\section{\TeX-related menu items}
50\label{tex-menus}
51
52\subsection{The model window}
53
54The fullest \TeX\ support in gretl is found in the GUI model
55window.  This has a menu item titled ``LaTeX'' with sub-items
56``View'', ``Copy'', ``Save'' and ``Equation options'' (see
57Figure~\ref{fig:latex-menu}).
58
59\begin{figure}[htbp]
60  \caption{\LaTeX\ menu in model window}
61  \label{fig:latex-menu}
62  \begin{center}
63    \includegraphics[scale=0.75]{figures/latex_menu}
64  \end{center}
65\end{figure}
66
67The first three sub-items have branches titled ``Tabular'' and
68``Equation''.  By ``Tabular'' we mean that the model is represented in
69the form of a table; this is the fullest and most explicit
70presentation of the results.  See Table~\ref{tab:mod1} for an example;
71this was pasted into the manual after using the ``Copy, Tabular'' item
72in gretl (a few lines were edited out for brevity).
73
74\begin{table}[htbp]
75\caption{Example of \LaTeX\ tabular output}
76\label{tab:mod1}
77\begin{center}
78
79Model 1: OLS estimates using the 51 observations 1--51\\
80Dependent variable: ENROLL\\
81
82\vspace{1em}
83
84\begin{tabular*}{.8\textwidth}{@{\extracolsep{\fill}}
85l% col 1: varname
86  D{.}{.}{-1}% col 2: coeff
87    D{.}{.}{-1}% col 3: sderr
88      D{.}{.}{-1}% col 4: t-stat
89        D{.}{.}{4}}% col 5: p-value (or slope)
90Variable &
91  \multicolumn{1}{c}{Coefficient} &
92    \multicolumn{1}{c}{Std.\ Error} &
93      \multicolumn{1}{c}{$t$-statistic} &
94        \multicolumn{1}{c}{p-value} \\[1ex]
95const &
96  0.241105 &
97    0.0660225 &
98      3.6519 &
99        0.0007 \\
100CATHOL &
101  0.223530 &
102    0.0459701 &
103      4.8625 &
104        0.0000 \\
105PUPIL &
106  -0.00338200 &
107    0.00271962 &
108      -1.2436 &
109        0.2198 \\
110WHITE &
111  -0.152643 &
112    0.0407064 &
113      -3.7499 &
114        0.0005 \\
115\end{tabular*}
116
117\vspace{1em}
118
119\begin{tabular}{lD{.}{.}{-1}}
120Mean of dependent variable & 0.0955686 \\
121 S.D. of dependent variable & 0.0522150 \\
122Sum of squared residuals & 0.0709594 \\
123Standard error of residuals ($\hat{\sigma}$) & 0.0388558 \\
124Unadjusted $R^2$ & 0.479466 \\
125Adjusted $\bar{R}^2$ & 0.446241 \\
126$F(3, 47)$ & 14.4306 \\
127\end{tabular}
128\end{center}
129\end{table}
130
131The ``Equation'' option is fairly self-explanatory---the results are
132written across the page in equation format, as below:
133
134%%% the following needs the amsmath LaTeX package
135
136\begin{gather}
137\widehat{\rm ENROLL} =
138\underset{(0.066022)}{0.241105}
139+\underset{(0.04597)}{0.223530}\,\mbox{CATHOL}
140-\underset{(0.0027196)}{0.00338200}\,\mbox{PUPIL}
141-\underset{(0.040706)}{0.152643}\,\mbox{WHITE}
142 \notag \\
143T = 51 \quad \bar{R}^2 = 0.4462 \quad F(3,47) = 14.431 \quad \hat{\sigma} = 0.038856\notag \\
144\centerline{(standard errors in parentheses)} \notag
145\end{gather}
146
147The distinction between the ``Copy'' and ``Save'' options (for both
148tabular and equation) is twofold.  First, ``Copy'' puts the \TeX\
149source on the clipboard while with ``Save'' you are prompted for the
150name of a file into which the source should be saved.  Second, with
151``Copy'' the material is copied as a ``fragment'' while with ``Save''
152it is written as a complete file.  The point is that a well-formed
153\TeX\ source file must have a header that defines the
154\texttt{documentclass} (article, report, book or whatever) and tags
155that say \verb|\begin{document}| and \verb|\end{document}|.  This
156material is included when you do ``Save'' but not when you do
157``Copy'', since in the latter case the expectation is that you will
158paste the data into an existing \TeX\ source file that already has the
159relevant apparatus in place.
160
161The items under ``Equation options'' should be self-explanatory: when
162printing the model in equation form, do you want standard errors or
163$t$-ratios displayed in parentheses under the parameter estimates?
164The default is to show standard errors; if you want $t$-ratios, select
165that item.
166
167\subsection{Other windows}
168
169Several other sorts of output windows also have \TeX\ preview, copy
170and save enabled.  In the case of windows having a graphical toolbar,
171look for the \TeX\ button.  Figure~\ref{fig:tex-icon} shows this icon
172(second from the right on the toolbar) along with the dialog that
173appears when you press the button.
174
175\begin{figure}[htbp]
176  \caption{\TeX\ icon and dialog}
177  \label{fig:tex-icon}
178    \begin{center}
179      \includegraphics[scale=0.75]{figures/texdialog}
180    \end{center}
181\end{figure}
182
183One aspect of gretl's \TeX\ support that is likely to be
184particularly useful for publication purposes is the ability to produce
185a typeset version of the ``model table'' (see
186section~\ref{model-table}).  An example of this is shown in
187Table~\ref{tab:modeltab}.
188
189\begin{table}[htbp]
190\caption{Example of model table output}
191\label{tab:modeltab}
192\begin{center}
193OLS estimates\\
194Dependent variable: ENROLL \\
195\vspace{1em}
196
197\begin{tabular}{lccc}
198 & Model 1  & Model 2  & Model 3 \\  [6pt]
199const & $\,\,$0.2907$^{**}$ & $\,\,$0.2411$^{**}$ & 0.08557 \\
200& \footnotesize{(0.07853)} & \footnotesize{(0.06602)} & \footnotesize{(0.05794)} \\ [4pt]
201CATHOL & $\,\,$0.2216$^{**}$ & $\,\,$0.2235$^{**}$ & $\,\,$0.2065$^{**}$ \\
202& \footnotesize{(0.04584)} & \footnotesize{(0.04597)} & \footnotesize{(0.05160)} \\ [4pt]
203PUPIL & $-$0.003035 & $-$0.003382 & $-$0.001697 \\
204& \footnotesize{(0.002727)} & \footnotesize{(0.002720)} & \footnotesize{(0.003025)} \\ [4pt]
205WHITE & $\,\,$$-$0.1482$^{**}$ & $\,\,$$-$0.1526$^{**}$ & \\
206& \footnotesize{(0.04074)} & \footnotesize{(0.04071)} & \\ [4pt]
207ADMEXP & $-$0.1551 & & \\
208& \footnotesize{(0.1342)} & & \\ [4pt]
209$n$ & 51 & 51 & 51 \\
210$\bar R^2$ & 0.4502 & 0.4462 & 0.2956 \\
211$\ell$ & 96.09 & 95.36 & 88.69 \\
212\end{tabular}
213
214\vspace{1em}
215Standard errors in parentheses\\
216{}* indicates significance at the 10 percent level\\
217{}** indicates significance at the 5 percent level\\
218\end{center}
219\end{table}
220
221
222\section{Fine-tuning typeset output}
223\label{tex-tune}
224
225There are three aspects to this: adjusting the appearance of the
226output produced by gretl in \LaTeX\ preview mode; adjusting the
227formatting of gretl's tabular output for models when using the
228\texttt{tabprint} command; and incorporating gretl's output into
229your own \TeX\ files.
230
231
232\subsection{Previewing in the GUI}
233
234As regards \emph{preview mode}, you can control the appearance of
235gretl's output using a file named \verb+gretlpre.tex+, which
236should be placed in your gretl user directory (see the \GCR).
237If such a file is found, its contents will be used as the ``preamble''
238to the \TeX\ source.  The default value of the preamble is as follows:
239
240\begin{code}
241\documentclass[11pt]{article}
242\usepackage[utf8]{inputenc}
243\usepackage{amsmath}
244\usepackage{dcolumn,longtable}
245\begin{document}
246\thispagestyle{empty}
247\end{code}
248
249Note that the \verb+amsmath+ and \verb+dcolumn+ packages are required.
250(For some sorts of output the \verb+longtable+ package is also
251needed.)  Beyond that you can, for instance, change the type size or
252the font by altering the \texttt{documentclass} declaration or
253including an alternative font package.
254
255In addition, if you wish to typeset gretl output in more than
256one language, you can set up per-language preamble files.  A
257``localized'' preamble file is identified by a name of the form
258\verb|gretlpre_xx.tex|, where \texttt{xx} is replaced by the first two
259letters of the current setting of the \texttt{LANG} environment
260variable.  For example, if you are running the program in Polish,
261using \verb|LANG=pl_PL|, then gretl will do the following when
262writing the preamble for a \TeX\ source file.
263
264\begin{enumerate}
265\item Look for a file named \verb|gretlpre_pl.tex| in the gretl
266  user directory.  If this is not found, then
267\item look for a file named \verb|gretlpre.tex| in the gretl
268  user directory.  If this is not found, then
269\item use the default preamble.
270\end{enumerate}
271
272Conversely, suppose you usually run gretl in a language other
273than English, and have a suitable \verb|gretlpre.tex| file in place
274for your native language.  If on some occasions you want to produce
275\TeX\ output in English, then you could create an additional
276file \verb|gretlpre_en.tex|: this file will be used for the preamble
277when gretl is run with a language setting of, say,
278\verb|en_US|.
279
280
281\subsection{Command-line options}
282
283After estimating a model via a script---or interactively via the gretl
284console or using the command-line program \app{gretlcli}---you can use
285the commands \texttt{tabprint} or \texttt{eqnprint} to print the model
286to file in tabular format or equation format respectively.  These
287options are explained in the \GCR{}.
288
289If you wish alter the appearance of gretl's tabular output for
290models in the context of the \texttt{tabprint} command, you can
291specify a custom row format using the \option{format} flag.  The
292format string must be enclosed in double quotes and must be tied to
293the flag with an equals sign.  The pattern for the format string is as
294follows.  There are four fields, representing the coefficient,
295standard error, $t$-ratio and p-value respectively.  These fields
296should be separated by vertical bars; they may contain a
297\texttt{printf}-type specification for the formatting of the numeric
298value in question, or may be left blank to suppress the printing of
299that column (subject to the constraint that you can't leave all the
300columns blank).  Here are a few examples:
301
302\begin{code}
303--format="%.4f|%.4f|%.4f|%.4f"
304--format="%.4f|%.4f|%.3f|"
305--format="%.5f|%.4f||%.4f"
306--format="%.8g|%.8g||%.4f"
307\end{code}
308
309The first of these specifications prints the values in all columns
310using 4 decimal places.  The second suppresses the p-value and prints
311the $t$-ratio to 3 places.  The third omits the $t$-ratio.  The last
312one again omits the $t$, and prints both coefficient and standard
313error to 8 significant figures.
314
315Once you set a custom format in this way, it is remembered and used
316for the duration of the gretl session.  To revert to the default
317formatting you can use the special variant \verb|--format=default|.
318
319
320\subsection{Further editing}
321
322Once you have pasted gretl's \TeX\ output into your own
323document, or saved it to file and opened it in an editor, you can of
324course modify the material in any wish you wish.  In some cases,
325machine-generated \TeX\ is hard to understand, but gretl's
326output is intended to be human-readable and -editable.  In addition,
327it does not use any non-standard style packages.  Besides the standard
328\LaTeX\ document classes, the only files needed are, as noted above,
329the \verb+amsmath+, \verb+dcolumn+ and \verb+longtable+ packages.
330These should be included in any reasonably full \TeX\ implementation.
331
332
333\section{Installing and learning \TeX}
334\label{tex-install}
335
336This is not the place for a detailed exposition of these matters, but
337here are a few pointers.
338
339So far as we know, every GNU/Linux distribution has a package or set
340of packages for \TeX, and in fact these are likely to be installed by
341default.  Check the documentation for your distribution.  For MS
342Windows, several packaged versions of \TeX\ are available: one of the
343most popular is MiK\TeX\, at \url{http://www.miktex.org/}.  For Mac OS
344X a nice implementation is i\TeX{}Mac, at
345\url{http://itexmac.sourceforge.net/}.  An essential starting point for
346online \TeX\ resources is the Comprehensive
347\TeX\ Archive Network (CTAN) at \url{http://www.ctan.org/}.
348
349As for learning \TeX, many useful resources are available both online
350and in print.  Among online guides, Tony Roberts' ``\LaTeX: from quick
351and dirty to style and finesse'' is very helpful, at
352
353\url{http://www.sci.usq.edu.au/staff/robertsa/LaTeX/latexintro.html}
354
355An excellent source for advanced material is \emph{The \LaTeX\
356  Companion} \citep{goossens04}.
357
358
359%%% Local Variables:
360%%% mode: latex
361%%% TeX-master: "gretl-guide"
362%%% End:
363