Browsed by
Category: LaTeX

Fix for LaTeX references in economics bibliography styles

Fix for LaTeX references in economics bibliography styles

The economic package includes old commands that are now deprecated within LaTeX. This caused me a problem using the AER bibliography style (aer.bst), and likely causes problems with other BibTeX styles too. My particular problem was with scrartcl refusing to recognise the \bf command rather than the newer \textbf version.

Very specifically, the problem was “Class scrartcl Error: undefined old font command `\bf’.”

The fix for this is simple. Just include the following two lines in the preamble of your document.

\DeclareOldFontCommand{\bf}{\normalfontbfseries}{\textbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\textit}

You could alternatively open up your *.bst file and manually change the code, but the two lines above should fix it.

LaTeX problem sets with hidden answers

LaTeX problem sets with hidden answers

I like being able to hide content in documents, for example including but not revealing the answers in a problem set. That makes it very easy to then produce the problem set solutions, simply by revealing the answers. I made this easier with a \hide{} command, that can be “turned off” so the answers are revealed.

This is the basic code I use for producing problem sets. The only change needed to convert a problem set into a solution set is to redefine the \showanswers variable to equal 1 rather than 0.

\documentclass{article}

% Set this =0 to hide, =1 to show
\def\showanswers{0}

\newcommand{\hide}[1]{
   \ifnum\showanswers=1

   #1 \vspace{\baselineskip}
   \fi

   \ifnum\showanswers=0
   \vspace{2\baselineskip} \hspace{2cm}
   \fi
}

\begin{document}

\begin{enumerate}
   \item This is question 1.
   \hide{Here is a hidden solution.}

   \item What is the answer to question 2?
   \hide{The answer is here.}
\end{enumerate}

\end{document} 
University of Tennessee beamer theme

University of Tennessee beamer theme

I’m teaching econometrics next semester, and did not want to simply regurgitate the textbook’s lecture slides. However, the University of Tennessee has a branding website, so I made a beamer theme that replicates the official UT PowerPoint template.

There is a little page for the theme here. You can download the files needed to install the theme here.

Cleaner euro symbol for LaTeX

Cleaner euro symbol for LaTeX

I typeset the euro symbol (€) regularly and I’ve always thought the version produced in LaTeX sticks out a bit like a sore thumb. (I re-assure myself that noticing these things is evidence that I adequately proof-read my prose.) The code below makes a new command \yuro that (in my opinion) fits in better with the surrounding text.

\documentclass[12pt]{article}
\usepackage{eurosym}
\usepackage{graphicx}
\newcommand{\yuro}{\scalebox{0.95}{\euro}}
\begin{document}
This is the size with the \euro 1,000 original configuration.

This is the size with the \yuro 1,000 newer configuration.
\end{document}

The code shrinks the size of the symbol to make it fit better with other characters. Similarities to the status of the eurozone are unintentional.

Petty’s “Taxes and Contributions” PDF

Petty’s “Taxes and Contributions” PDF

I have generated an easy-to-read PDF of William Petty’s Taxes and Contributions. You can download it here.

Hard copies of the book, comprising poor photocopies of older editions, make difficult work on the eyes. This edition is typeset as a modern document. I did write a script to generate it though, so it’s likely that there are some errors in there. Please let me know if you find any.

Due credit to the nice people from McMaster University who transcribed the plain-text copy.

Lagrange multiplier symbol code

Lagrange multiplier symbol code

Economists often denote a Lagrangian maximization problem with a scripted L. Unless you exert a little bit of effort, this looks poorly when produced by LaTeX. The code below allows you to easily typeset the symbol in a larger font-size.

The code creates four new commands: \lagrange1, \lagrange2, \lagrange3, and \lagrange4. They produce the “Lagrangian L” with increasing size.

\documentclass{article}

\usepackage{relsize}
\usepackage{mathrsfs}
\usepackage{xstring}

\newcommand{\lagrange}[1]{\IfEqCase{#1}{{1}{\mathscr{L}}{2}{\mathlarger{\mathscr{L}}}{3}{\mathlarger{\mathlarger{\mathscr{L}}}}{4}{\mathlarger{\mathlarger{\mathlarger{\mathscr{L}}}}}}}

\begin{document}
$$ \lagrange1 $$
$$ \lagrange2 $$
$$ \lagrange3 $$
$$ \lagrange4 $$
\end{document}
Fitting tables to the width of a page

Fitting tables to the width of a page

Ever have the problem of Stata regression output being a little too wide? Worry no more.

I use Ben Jann’s excellent esttab to export Stata regressions into LaTeX documents.

My only problem with esttab is that the tables can be too wide, i.e. wider than the width of the text in the PDF. So I made a few edits to esttab that automatically scale the tables to the text-width.

I have called this program estwide. You can download it here. As it is based on estout, Ben Jann should be considered a co-author. Click here to see an example of its effect. (If you wish to replicate the above example, you can download the associated do-file here and the TeX file here.)

To use estwide:
1. Make sure estout is installed. To do this, in Stata type ssc inst estout, replace
2. Save estwide.ado to the same folder that estout is now installed in. You can check the folder by typing which estout
3. Restart Stata.
4. Rather than exporting your tables using the esttab command, simply replace esttab with estwide, e.g. estwide using hello.tex, style(tex) replace
5. Make sure you have both the adjustbox and booktabs LaTeX packages installed.
6. Make sure you have called both of these packages up by including \usepackage{booktabs} and \usepackage{adjustbox} in the header of your LaTeX file.
7. Include your tables as normal. You can copy and paste the output into your TeX file, or have the tables update automatically when you make changes by using \input{myfilename}.

Partial derivative shortcut in LaTeX

Partial derivative shortcut in LaTeX

This is incredibly simple code but may be of use to some people. Typing out derivatives in LaTeX (e.g. \frac{\partial y}{\partial x}) can be shortened.

Add this line of code to the header of your document:

\newcommand{\dydx}[2]{\frac{\partial{#1}}{\partial{#2}}}

This creates a new command \dydx that takes two arguments, e.g. \dydx{P}{\tau}. Include this command in math mode (e.g. encased in dollar signs) and it will produce \frac{\partial P}{\partial \tau}.

Some help with common LaTeX problems

Some help with common LaTeX problems

What’s the easiest way to include a graphic (or graph, diagram, figure etc.) in my document?

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\caption{This is my picture}
\includegraphics[width=5in,height=3in]{adamsmith.jpg}
\end{figure}
\end{document}

Then compile using pdflatex.

I’m getting a “no BoundingBox” error when I compile my document.

Have you tried compiling the document with pdflatex? In WinEdt, select PDFLaTeX from the dropdown menu that’s below ‘Accessories’ on the menu bar, and to the right of the recycle bin icon. If you’re compiling from the command prompt and your document is named thesis.tex, type pdflatex thesis.

I’m trying to compile my document and I am using natbib to do the references, but the document won’t compile with PDFLaTeX.

It’s unfortunate that natbib (as far as I can see) relies on latex (not pdflatex) but latex gets confused if you have graphics in the document. My workaround for this is to temporarily place a % sign in front of any graphics to turn them into comments, rather than code. This means the graphics are initially excluded, and you can run latex/bibtex and natbib will work. Once all the references are good and ready, you can remove the % signs (a quick Find > Replace All will do the trick) and compile using pdflatex.

Simple Problem Set Hack

Simple Problem Set Hack

I had a problem set where each question had multiple sub-parts: a, b, c; etc. I was typing the solution up in LaTeX and it wasn’t obvious what was the cleanest way to identify my answers.

I ended up with code like this:

\section*{Question 1}
\new This is my answer to part a.

\new This is my answer to part b

This formatting results in something like this:

That’s exactly what I was looking for. It requires two lines of code at the start of your document:

\newcounter{my_count}
\newcommand{\new}{\vspace{0.3cm}\addtocounter{my_count}{1} (\alph{my_count}) }