31
votes
How to highlight (color/draw attention to) a particular snippet in Minted
You can highlight certain lines with highlightlines={1,2-3,5-10}, e.g.
\begin{minted}[highlightlines={1,3-4,6-10}]{python}
def f(x):
y = x ** 2
return y
def f(x):
y = x ** 2
return y
...
22
votes
Best practices for source file line lengths?
I'll use an example from the TeXBook source
This manual is intended for people who have never used \TeX\ before, as
well as for experienced \TeX\ hackers. In other words, it's supposed to
be a ...
19
votes
Accepted
How to highlight (color/draw attention to) a particular snippet in Minted
The minted documentation has an example using escapeinside. I’m just copying it here:
\begin{minted}[escapeinside=||]{py}
def f(x):
y = x|\colorbox{green}{**}|2
return y
\end{minted}
...
17
votes
Can someone explain what is labxx in the source code of tex
The file you are looking at is not really "source code" it is tex0.c which is C derived (by web2c) from the tex.web source code of TeX, which is written in web (documented pascal).
Almost ...
16
votes
Why can't TeX Live's size be reduced?
[Slightly tangential but perhaps useful.] The LaTeX3 team have recently set up an automated test system which needs to install 'just enough' TeX Live to work. That's done using a script but the key ...
15
votes
Adding background color to \verb or \lstinline command without \Colorbox
You can patch \lstinline to use \Colorbox; of course you lose the possibility to break lines in \lstinline.
\documentclass{article}
\usepackage{xpatch}
\usepackage{xcolor}
\usepackage{listings}
\...
13
votes
Best practices for source file line lengths?
The main problem is here that the error messages gives you the line number in which line the error was found. That means it could be in that line or the lines before.
If you have long or very long ...
13
votes
Best practices for source file line lengths?
TeX engines can essentially deal with lines of any (reasonable) length so in that sense there is no forced limitation and starting new lines largely comes down to personal preferences and your ...
13
votes
Adding background color to \verb or \lstinline command without \Colorbox
(I rewrote this answer after the OP indicated that he/she was mainly interested in having all instances of \lstinline colored automatically, i.e., without having to encase the instances in explicit \...
10
votes
Accepted
Moving arguments and \protect: coming to grips with the definitions
A 'moving' argument is where the argument to some LaTeX command will be 'moved around', either by writing it to a file, writing it to a message or by otherwise fully-expanding it. The confusion likely ...
10
votes
Accepted
What does the \afterassignment do in the following macro from the TikZ source code?
It is similar to \futurelet in that it \let s the command name to the following token (ignoring one optional space) but unlike \futurelet it consumes the token
\documentclass{article}
\def\zza{\...
10
votes
Accepted
Reading LuaTeX source
The master luatex svn sources are currently not at a publicly accessible location, I understand that this is an essentially temporary situation due to a change of hosting arrangements however the ...
10
votes
Accepted
Where's the mandatory argument of sectioning commands?
Let's take the example of \section (all of them behave more or less the same, except for \chapter and \part). The definition is:
\newcommand\section{\@startsection {section}{1}{\z@}%
{-3....
9
votes
Accepted
Listing source code in two columns
The example is generated by using the fancyvrb package. You can put the codes in two minipages and mimic a two column layout. Also note that the line numbers are somewhat misplaced; a solution is ...
9
votes
Best practices for source file line lengths?
I'll break this down into two cases:
1. When defining macros, drawing tikz pictures and othwerwise writing mostly code:
Short lines work well. Not necessarily one statement per line as is ...
9
votes
Accepted
Is it safe to define \@nil?
Most uses of \@nil just use \@nil as a macro argument delimiter so it doesn't matter what the definition is, however this is intentionally undefined. If you have code that is trying to execute \@nil ...
9
votes
Accepted
Is there a newmarks command?
If you're talking LaTeX, then \newmarks is there:
> latexdef newmarks
\newmarks:
macro:->\e@alloc \marks \e@alloc@chardef {\count 256}\m@ne \e@alloc@top
However \newmarks\thingy requires ...
8
votes
Accepted
Is there such a thing as a LaTeX code formatter
I created a website that formats the latex code to make indents look correct.
The general idea of the website is to make sure you can read the code.
It also provides table indentations. I am still ...
8
votes
Accepted
How to embedded source code on-demand into PDF?
Yes, you may embed your source code as a file in the pdf. I'm using usually the package attachfile, but there are some more, the embedfile package e.g. or attachfile2.
Using attachfile I'm printing ...
8
votes
Accepted
How to use true/false inside definitions?
The two constructs aren't equivalent.
With
\if@mybool
\def\ps@myps{...T...}%
\else
\def\ps@myps{...F...}%
\fi
you test \if@mybool and define \ps@myps according to its truth value. Changing the ...
8
votes
Two spaces in LaTeX code
No. Multiple consecutive spaces are gobbled into a single space within the code, unless they are hard coded (like using ~ or \ - a control space - or via \hspace, or ...).
The setting of it might ...
8
votes
Accepted
LaTeX code formatting regarding placement of floats and where best to place figures with respect to main body text references
This is probably no more than an expanded comment, but it does benefit from experience in juggling floats in TUGboat for (my idea of) best effect. Details of the rules of float placement are given in ...
7
votes
How to upload my moduled tex files in arXiv?
It should work if you:
add %auto-ignore to the first line of every text file but the main file
compress your file tree
prevents arXiv's system from compiling your non-main files independently
...
7
votes
Does the tab key do anything?
Let's look at latex.ltx, where we find
277 \catcode`\{=1 % left brace is begin-group character
278 \catcode`\}=2 % right brace is end-group character
279 \catcode`\$=3 % dollar sign is math shift
280 ...
7
votes
Accepted
Where is \scope defined in the TikZ source code?
In the setup of TikZ environment \tikz@installcommands is invoked.
%
% Main TikZ Environment
%
\def\tikzpicture{%
\begingroup%
\tikz@startup@env%
\pgfutil@ifnextchar[\tikz@picture{\tikz@...
7
votes
Accepted
The meaning of two seemingly undefined control-sequences in the PGF source code
This is just the way TeX handles ifs. Further up you'll find
\newif\ifpgfutil@in@
The statements
\pgfutil@in@true
\pgfutil@in@false
have the effect to redefine \ifpgfutil@in@ to \iftrue and \...
7
votes
Accepted
LaTeX(2e) Programming vs. expl3 (which to learn)
Although I think that the question is quite broad, I try to answer it with the focus on package and class writing. I will use shortened versions of your questions:
Is it worth to learn the stable ...
7
votes
Accepted
Can one customize lstlisting environment?
The following code does the trick for the three keywords; as far as I can remember, the listings package makes no provision for coloring the numbers in the code.
\documentclass[a4paper]{article}
\...
7
votes
Accepted
How to emphasize in a listing and keep source columns aligned?
You can hack into the commands for [i] type delimeters, \lst@BeginIDelim and \lst@EndIDelim. It would be nicer to add a new delimeter type, but this would require redefining a lot of internal commands....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sourcecode × 351listings × 84
minted × 26
code × 26
verbatim × 17
formatting × 15
macros × 14
best-practices × 14
tikz-pgf × 13
beamer × 11
color × 10
highlighting × 10
tools × 10
spacing × 9
pdftex × 9
pdf × 9
environments × 8
line-breaking × 8
syntax × 8
math-mode × 7
packages × 7
lyx × 7
comments × 7
source × 7
fonts × 6