{sourcecode} is a collection of computer instructions, here for (La)TeX.

learn more… | top users | synonyms

128
votes
4answers
5k views

What is the use of percent signs (%) at the end of lines?

I see that the code in many packages and examples contains percent signs % at the end of (many) lines. What are they used for? Do they affect the parsing of those lines?
55
votes
5answers
4k views

Tool for cleaning LaTeX code

Is there something like indent for LaTeX? I have a collaborator that is using Scientific Workplace and the code it produces is totally messed up; I know I shouldn't expect miracles, but any machine ...
54
votes
4answers
3k views

Defining custom commands is bad style?

I recently received this in a e-mail from my professor Good LaTeX style would preclude creating any of your own commands, counters, etc. (Most journals would reject submissions with user-defined ...
50
votes
9answers
2k views

What are the pros and cons of using hard wrapping, and why is it so common with LaTeX?

It seems that hard-wrapping - i.e. inserting a newline when the line reaches a certain threshold - is extremely common in the LaTeX source when writing technical papers, either by manually inserting ...
46
votes
5answers
5k views

How can I see the “implementation” of the \LaTeX command?

After reading another question relating to how to see definitions of commands, I tried: \documentclass{article} \begin{document} \show\LaTeX \end{document} But this shows me in my logfile: ...
38
votes
2answers
2k views

Styleguide for LaTeX similar to the Google styleguides?

Even though I don't work at Google, the Google Styleguides have been very helpful for me in adopting consistent, readable style conventions for my code. Unfortunately, there is no Google Styleguide ...
28
votes
2answers
830 views

Are comments safely hidden once the document is compiled?

This is kind of similar to some of the pdf to latex questions but from a different angle. I'm not looking for a complete LaTeX reconstruction method, I want to know if the comments are safely hidden. ...
25
votes
2answers
1k views

What are coding conventions in LaTeX?

What do I mean by Convention? First of all, allow me to clear myself about the word 'conventions. As most of you already know, coding conventions are a set of guidelines for a specific programming ...
24
votes
2answers
864 views

How to understand and write LaTeX code?

LaTeX is like a language. In order to write LaTeX code I have to understand the "word" and the "sentences structure". I have searched on wiki, some LaTeX books, but they just give the LaTeX command, ...
20
votes
6answers
968 views

Why doesn't LaTeX interpret `(` as `\left(` and `)` as `\right)`?

First of all I love LaTeX/MathJax; I use it a lot, but there are couple of things I hate about it. Sometimes the code becomes so messy that I almost can't read it without looking at the output, while ...
20
votes
3answers
2k views

When can I safely add an empty line?

I really like spacing my LaTeX to stay organized, but I'm always scared that adding a space will affect the output when all I really wanted to do was separate the "code" a bit. So most of the time I ...
20
votes
1answer
1k views

Pretty printing of LaTeX code

In many MWE here on TeX.SE the LaTeX code is written without explanatory comments and as compact as possible. An Example: \documentclass[ngerman,fontsize=12pt,pagesize]{scrreprt} ...
15
votes
2answers
463 views

Location inside a LaTeX source code

When viewing a pdf of a long LaTeX document, it can sometimes be difficult to find where a certain equation or a line in the pdf is located in the source code, as there are no page numbers in the ...
15
votes
2answers
2k views

Colored background in inline listings

I would like to make inline code more distinguishable from the text surrounding it, and I thought that using a background might work (like it is done on the stackexchange pages.) Since I use the ...
15
votes
1answer
419 views

Are there guidelines on how to read commented sources of LaTeX packages?

I'm trying to read source2e.pdf (texdoc source2e on the command line), but I'm stumped. It seems a rather mysterious tome to me. As I understand from this answer about what arguments a command ...
14
votes
1answer
953 views

Why can't TeX Live's size be reduced?

I understand that the following question has been answered Why is the MacTeX distribution so large? Is there anything smaller for OS X? but my question differs from it. I just installed MacTeX and ...
14
votes
1answer
220 views

How does minted work from a point of LaTeX-User?

The package minted is one of the most famous package for highlighting source code. But how does it work?
12
votes
1answer
568 views

Is there such a thing as a LaTeX code formatter

I was looking for this a while back for JavaScript, but I was wondering a general purpose one exists for all, or most languages. For example for LaTeX I would put the following in a text box ...
11
votes
3answers
4k views

How display LaTeX code in LaTeX document?

I'm making Beamer presentation. How I can display LaTeX code inside presentation?
11
votes
1answer
1k views

Where I can find the source code of pdflatex.exe?

Where I can find the source code of pdflatex.exe? Edit 1 This is quoted from the link given by @TH. pdfTeX is built on top of TeX, written by Donald Knuth cum suis (Liang and so), and eTeX, ...
10
votes
3answers
431 views

Empty line (in code) before enumerate environment

I like my code to look like this: \documentclass{article} \begin{document} \begin{enumerate} \item test text \begin{enumerate} \item 1 \item 2 \item 3 \item 4 \item 5 ...
10
votes
1answer
1k views

What are the standard styles to format LaTeX source code?

In any other programming languages, we have several ways to format our source code. For example, some of the standard styles are: Allman(ANSI) K&R GNU .... Within LaTeX, I couldn't find a neat ...
10
votes
1answer
1k views

Source Code Indentation

I was wondering if it is possible to indent the code like in most programming languages as shown below: \part \chapter \section \subsection etc. This would make the ...
10
votes
1answer
1k views

Numbers and programming code

This happens when I use programming code and enumeration, how can I add a gap between the numbering and the line numbers of the code. I'm using this in LaTeX Preamble: \usepackage{listings} ...
9
votes
2answers
544 views

What are good packages / techniques for writing more readable LaTeX *code*?

A while ago I stumbled upon the semantic package --- its 'math ligatures' feature in particular --- and the whole way in which I write math-code in LaTeX changed. Instead of \[ \sem{\sigma}_s^x ...
9
votes
2answers
143 views

Can spaces at the beginning of a line ever cause problems?

To structure my sourcecode, I often use spaces for padding: \newcommand{\st}[1]{% \begin{tabular}{lr} \emph{Student} & \emph{Score}\\ #1 \end{tabular}% } Can this ever cause ...
9
votes
2answers
5k views

What's the best way to typeset C++ codes in latex?

I'm participating in a programming contest and we are allowed to prepare a team reference document which must not exceed 25 pages. Typically we will prepare many code templates and this year I'm ...
9
votes
1answer
7k views

How to create beamer slides with source code that can be copied?

We are converting our course slides from Powerpoint to LaTeX, to be able to offer all code in a more open format and to let students easily copy code from the slides. However, the latter does not seem ...
8
votes
3answers
587 views

Writing source code in LaTeX as text

Is there a package that allows source code in LaTeX as text? I rather not use listings package because the code takes too much space. Copy/paste is tedious because the spaces are not preserved.
8
votes
3answers
5k views

How to put C++ source code into beamer slides [duplicate]

Possible Duplicate: How display LaTeX code in LaTeX document? How do I fit java style source code in one frame in beamer? How do I add C++ formatted and coloured source code to my beamer ...
8
votes
2answers
203 views

safe places to skip lines in the source

Ideally, I would like to be able to skip lines before and after \section, before and after many environments (theorem, itemize, enumerate, etc.), between \items in a list, before and after ...
8
votes
2answers
702 views

TeXShop: Force spaces instead of tabs

Is there a way to make TeXShop insert an arbitrary number of spaces when I press the tab key instead of inserting a tab? This functionality is in TeXnicle and I really like it, but TeXShop is my ...
8
votes
1answer
146 views

Where can I find a manual for learning the fundamental background of LaTeX source?

I would like to know if there is some manual from which I can learn the bases of LaTeX programming language. I need something universal, not related to some specific package or class, that at the end ...
8
votes
1answer
3k views

Insert code or text file in latex as is?

Question : How can I insert a txt file ( a source code) as such in latex without any change in indentation, tabs, formatting etc? Scenario : Consider I have a text file as below ( It is a part of a ...
7
votes
2answers
918 views

Folding entire section in AUCTeX?

I'm new to AUCTeX and I wonder: is it possible to fold entire sections or subsections of a LaTeX document for a better overview, so that they are only represented by their headline (kind of a tree ...
7
votes
1answer
149 views

Display of source code in customised (IDE-like) format in PDFLaTeX

I want to put some “C” source code snippets in latex (I am using PDFLaTeX), but I don’t get the result that I want using the “listings” package. What ideally would like to get is the same result as ...
7
votes
3answers
240 views

Expanding a minted command inside a macro

I am currently trying to speed up the compile time of a document that uses minted. I would like to be able to have certain language features (and style) appear the same in both a minted environment ...
7
votes
1answer
125 views

Could significant speedups be gained from package code minification?

Wikipedia: Minification is (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code ...
7
votes
1answer
411 views

Clean black & white style for minted

I'm using minted to format code in a book. Except for the bw theme, I only see colored styles, which is nice for producing a PDF, but not ideal for printing in black & white. Is there a clean ...
7
votes
1answer
239 views

How would I recursively add the document source code to an appendix?

For kicks, I would like to include the source code as an appendix. It's rather superfluous, yes, but it's puzzling. I commonly have documents that are structured thusly: main.tex includes: ...
6
votes
1answer
377 views

Is there an alternative to LaTeX which isn't whitespace sensitive?

I have been using LaTeX for about a year now, and I quite like it. However, I like to space out my source code. In most languages, this doesn't cause an issue, as extra newlines don't affect meaning. ...
6
votes
2answers
324 views

C++ operators ^=, <<=, >>= misinterpreted

I write a list of C/C++ operators of the following form : \texttt{operator+=}, \texttt{operator-=}, \texttt{operator*=}... The problem is that \texttt{operator\^=}, \texttt{operator>>=}, ...
6
votes
2answers
158 views

How to make a new line in the source file but not the output

I want to adhere to the traditional '80 character' line length limit in my .tex source file. How do I do a new line in the source but not in the document output?
6
votes
2answers
164 views

Should I use a space or a new line after a period?

After a period in a .tex file, within a paragraph, should I use a space or a new line? I.e. like this: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec rhoncus vestibulum metus ut ...
6
votes
2answers
310 views

Comparing two versions of programming code with LaTeX

I'd like to compare two versions of program with vertical line between them. How can I do this with LaTeX?
6
votes
2answers
414 views

How to put source code in a LaTeX table?

I am comparing source in a paper and I would like to put them in a table, so the differences are easily spotted. I used the following LaTeX code: \begin{tabular}{ | l | l | l |} Option 1 & ...
6
votes
1answer
320 views

How can I get proper Matlab syntax when typesetting Matlab source code using the algorithm package?

I'm currently using the algorithm package for typesetting Matlab source code in my document. However, the way keywords are typeset doesn't match the Matlab syntax. For instance, \EndFor is typeset as ...
6
votes
1answer
178 views

Where to find LaTeX commands source code?

I would like to know where can I find the definition of an original command. That is, let's say I want to redefine the command \ref so when I type it, instead of showing just the number of the label ...
6
votes
1answer
533 views

How to Format C Program Code Block Nicely

I am using the following settings to format my code blocks: % xxxxxxxxxxxxxxxxxxxxxxxxx Code Snippet STARTS xxxxxxxxxxxxxxxxxxxxxx \lstset{ language=C, % choose the language of ...
6
votes
1answer
203 views

Reference line in document's own source code

I am commenting on a LaTeX document (with todonotes), and I would like to put a reference to a line in the source code, writing e.g.: See the code around line 123 of foo.tex to please fix this ...