latex interview questions
Top latex frequently asked interview questions
I'm trying to enter some UTF-8 characters into a LaTeX file in TextMate (which says its default encoding is UTF-8), but LaTeX doesn't seem to understand them. Running cat my_file.tex
shows the characters properly in Terminal. Running ls -al
shows something I've never seen before: an "@" by the file listing:
-rw-r--r--@ 1 me users 2021 Feb 11 18:05 my_file.tex
(And, yes, I'm using \usepackage[utf8]{inputenc}
in the LaTeX.)
I've found iconv
, but that doesn't seem to be able to tell me what the encoding is -- it'll only convert once I figure it out.
Source: (StackOverflow)
My LaTeX makes me pagebreaks after each subsection because my subsections are in separate files. I use the command \include{file}
which adds a pagebreak after the use of it.
I would like to have no pagebreak caused by the use of \include{file}
.
How can you no pagebreak after the use of include
-command?
Source: (StackOverflow)
My equation is very long. How do I get it to continue on the next line rather than go off the page?
Source: (StackOverflow)
This is a pretty basic question but... How do you write a URL in Latex? The subscripts and everything else make the font look very strange when it compiles.
Source: (StackOverflow)
In LaTeX, how can I define a string variable whose content is used instead of the variable in the compiled PDF?
Let's say I'm writing a tech doc on a software and I want to define the package name in the preamble or somewhere so that if its name changes, I don't have to replace it in a lot of places but only in one place.
Source: (StackOverflow)
I am currently building a presentation using LaTeX beamer. Is there a way to hide the presentation controls on the bottom of the slides? I don't use those controls, and they sometimes collide with the slide's text.
Source: (StackOverflow)
I am creating a report in LaTeX which involves a few tables. I'm stuck on that as my cell data in the table is exceeding the width of the page. Can I somehow wrap the text so that it falls into the next line in the same cell of the table?
Is it somehow related to the table's width? But as it's overshooting the page's width, it won't make a difference, will it?
Source: (StackOverflow)
On general request, a community wiki on producing latex tables in R. In this post I'll give an overview of the most commonly used packages and blogs with code for producing latex tables from less straight-forward objects. Please feel free to add any I missed, and/or give tips, hints and little tricks on how to produce nicely formatted latex tables with R.
Packages :
- xtable : for standard tables of most simple objects. A nice gallery with examples can be found here.
- memisc : tool for management of survey data, contains some tools for latex tables of (basic) regression model estimates.
- Hmisc contains a function
latex()
that creates a tex file containing the object of choice. It is pretty flexible, and can also output longtable
latex tables. There's a lot of info in the help file ?latex
- miscFuncs has a neat function 'latextable' that converts matrix data with mixed alphabetic and numeric entries into a LaTeX table and prints them to the console, so they can be copied and pasted into a LaTeX document.
- texreg package (JSS paper) converts statistical model output into LaTeX tables. Merges multiple models. Can cope with about 50 different model types, including network models and multilevel models (lme and lme4).
- reporttools package (JSS paper) is another option for descriptive statistics on continuous, categorical and date variables.
- tables package is perhaps the most general LaTeX table making package in R for descriptive statistics
- stargazer package makes nice comparative statistical model summary tables
Blogs and code snippets
Related questions :
Source: (StackOverflow)
Absolute beginner LaTeX question here:
How do you change the font for the whole document to sans-serif (or anything else)?
Source: (StackOverflow)
I'm writing a very long document in LaTeX. I have my work computer and my laptop, and I work on them both. I need to keep all the files synchronized between the two computers, and also would like to keep a revision history. I chose git as my DVCS, and I'm hosting my repository on my server. I'm also using Kile + Okular to do the editing. Kile doesn't have an integrated git plugin. I'm also not collaborating with anyone on this text. I'm also thinking about putting another private repository on codaset, if my server for some reason is not accessible.
What is the recommended workflow practice in this case? How can branching be fitted in this working scheme? Is there a way to compare two versions of the same file? What about using a stash?
Source: (StackOverflow)
How can I prevent LaTeX from inserting linebreaks in my \texttt{...}
or \url{...}
text regions? There's no spaces inside I can replace with ~
, it's just breaking on symbols.
Update: I don't want to cause line overflows, I'd just rather LaTeX insert linebreaks before these regions rather than inside them.
Source: (StackOverflow)
How should a latex source code listing look like to produce an output like in known books, for example one for the Spring Framework? I've tried with the latex listings package but wasn't able to produce something that looked as nice as the one below. So I'm primarely interested in the formatting instructions to produce something like the sample below (from Manning's sample chapter for Spring in Action):

EDIT
With the help especially of Tormod Fjeldskår here's the complete snippet to produce the desired look:
\usepackage{listings}
\usepackage{courier}
\lstset{
basicstyle=\footnotesize\ttfamily, % Standardschrift
%numbers=left, % Ort der Zeilennummern
numberstyle=\tiny, % Stil der Zeilennummern
%stepnumber=2, % Abstand zwischen den Zeilennummern
numbersep=5pt, % Abstand der Nummern zum Text
tabsize=2, % Groesse von Tabs
extendedchars=true, %
breaklines=true, % Zeilen werden Umgebrochen
keywordstyle=\color{red},
frame=b,
% keywordstyle=[1]\textbf, % Stil der Keywords
% keywordstyle=[2]\textbf, %
% keywordstyle=[3]\textbf, %
% keywordstyle=[4]\textbf, \sqrt{\sqrt{}} %
stringstyle=\color{white}\ttfamily, % Farbe der String
showspaces=false, % Leerzeichen anzeigen ?
showtabs=false, % Tabs anzeigen ?
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
%backgroundcolor=\color{lightgray},
showstringspaces=false % Leerzeichen in Strings anzeigen ?
}
\lstloadlanguages{% Check Dokumentation for further languages ...
%[Visual]Basic
%Pascal
%C
%C++
%XML
%HTML
Java
}
%\DeclareCaptionFont{blue}{\color{blue}}
%\captionsetup[lstlisting]{singlelinecheck=false, labelfont={blue}, textfont={blue}}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\textwidth}{\hspace{15pt}#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
Use it with this in your document:
\lstinputlisting[label=samplecode,caption=A sample]{sourceCode/HelloWorld.java}
Source: (StackOverflow)
I need to highlight source code in LaTeX. The package listings
seems to be the best choice for most use-cases and for me it was, until now.
However, now I need more flexibility. Generally, what I’m looking for is a real lexer. In particular, I need (for an own language definition) to define (and highlight!) own number styles. listings
does not allow highlighting numbers in code. However, I need to produce something like this:

listings
also cannot cope with arbitrary delimiters for strings. Consider the following valid Ruby code:
s = %q!this is a string.!
Here, !
can be replaced by almost any delimiter.
(That listings
cannot handle Unicode is also quite vexing, but that’s another issue.)
Ideally, I am looking for an extension of listings
that allows me to provide more complex lexing rules. But barring that, I am also searching for viable alternatives.
Other threads have suggested using Pygments which can produce LaTeX output. There’s even a package – texments
– to ease the transition.
However, this sorely lacks features. In particular, I am interested in listings
-style line numbering, source code line references, and the possibility of embedding LaTeX in source code (options texcl
and mathescape
in listings
).
As an example, here’s a source code typeset with listings
which shows some of the things that a replacement should also provide:
[“Sideways addition” modified from Bit Twiddling Hacks]
Source: (StackOverflow)
I've been using Markdown for class notes, and it's great. I even do some preprocessing on the Markdown so I can do things like tables. But this term I'm teaching a class with a lot of math, and I'd love to be able to put LaTeX formulas with Markdown, something like this:
The refinement relation is written $a \sqsubseteq b$, which can be
pronounced "$a$ approximates $b$" or "$b$ is at least as defined as $a$".
I'd like to be able to take each fragment of LaTeX and preprocess it into a nice antialiased PNG file which I could then include in my Markdown via the HTML <img>
tag. But I have absolutely no idea how to take a fragment of LaTeX and get a nice image that
- Has the right bounding box
- Is antialiased
All I know how to do is get full pages in DVI, PostScript, or PDF formats.
I'm sure this problem has been addressed, but I haven't been able to guess the right search terms. Any suggestions how to solve it or where to look for an existing solution?
EDIT: Having installed mathTeX, I can say that the code is inflexible, that it violates the Linux Filesystem Hierarchy standard, and that it is amateur work—in both the good and bad senses of that word. The code is so complex that there are no obvious faults. I will be looking for alternatives.
Also, it's clear that at bottom, solutions are based on dvipng
.
ONE YEAR LATER: I never did get the seamless integration I had been hoping for, but I am limping along on a script of my own devising. It turns out that instead of dvipng
it is a little easier to use dvips -E
and the convert
program of ImageMagick. The benefits are slightly more control of things like scaling, and ease of making a transparent background.
The curious can inspect this example.
I can't recommend this solution to anyone. But I can't recommend MathTeX either.
Source: (StackOverflow)