Code
A source listing in a monospace font, with the keywords of its language emphasised.
Writing code
Insert a Code block and type or paste your code. Spaces, indentation and blank lines are kept exactly as you write them.
Tabindents by two spaces.Enteradds a line — a blank line is ordinary in code.Escleaves the listing and continues below it.Backspacein an empty listing deletes the block.
Language
Choose the language in the right column. It decides which words are treated as keywords.
Plain text, Python, C, C++, Java, SQL, Bash, R, Matlab, Fortran and LaTeX.
Only the languages the LaTeX listings package knows are offered. For anything else — JavaScript, TypeScript, Go, Rust, JSON, YAML, HTML… — use Plain text: the code is printed in monospace, without emphasis.
Line numbers
Switch Line numbers to Numbered to print a number in front of each line.
How it looks in the PDF
- Monospace, slightly smaller than the text.
- Keywords in bold, comments in italics. There is no colour: the editor highlights exactly what the PDF will emphasise, no more.
- Long lines wrap at the right margin instead of running off the page, in the PDF as in the editor.
- A listing can break across pages.
What it cannot do
- No colour and no themes.
- No caption, no number, no cross-reference. A listing is not "Listing 1".
- No highlighted or emphasised lines.
- No inline code. There is no monospace format for a word inside a sentence.
- Special characters are limited. Common accented letters (é, à, ü) are fine, but typographic characters — curly quotes ’ “ ”, dashes — –, the ellipsis …, œ, €, « » — are missing or wrong in a listing. Use straight quotes and plain hyphens in code and comments.
- A code block cannot be placed inside a theorem. It can be placed in a column.
- An empty listing prints nothing.
What it prints
The code itself is stored in a file next to the source, which is what keeps every character of it literal:
\lstinputlisting[basicstyle=\ttfamily\small,breaklines=true,
showstringspaces=false,keywordstyle=\bfseries,commentstyle=\itshape,
numbers=none,language={Python}]{listings/….txt}