Code Listings

We will be illustrating all of our examples with code listings in this tutorial, so let’s first show how to set them up.

An example setup which you can add to your header.tex file is:

\label{lst:setup}
\usepackage{listings}
\lstset{ %
  backgroundcolor=\color{white},   % choose the background color
  basicstyle=\footnotesize,        % size of fonts used for the code
  breaklines=true,                 % automatic line breaking only at whitespace
  captionpos=b,                    % sets the caption-position to bottom
  commentstyle=\color{OliveGreen},    % comment style
  keywordstyle=\color{BlueViolet},       % keyword style
  stringstyle=\color{black},     % string literal style
  language=[AlLaTeX]TeX,             % Set your language (you can change the language for each code-block optionally)
  frame=lrtb, %
  xleftmargin=\fboxsep, %
  xrightmargin=-\fboxsep, %
  moretexcs={lstset,color,colorlet, cellcolor, newcolumntype, columncolor, rowcolor, multirow, xspace, LaTeX, TeX},
}

Useful to keep in mind: definitions in your header.tex file are global to your article, while macros introduced in a paragraph are only local to that paragraph. That applies even to global commands such as \gdef , as Authorea processes each paragraph independently of its surroundings. To create and edit your header.tex file, follow these instructions.