Questions tagged [code]

{code} is about using LaTeX to format and display source code. For questions about TeX itself as a programming language, use the {programming} tag.

is about using LaTeX to format and display source code. For questions about TeX itself as a programming language, use the tag.

Formatting source code in LaTeX can be done in several ways:

  1. The environment is the most basic.
  2. makes verbatim environments much more customizable, and allows pre-processing of its input. More information: fancyvrb package documentation.
  3. is probably the most popular choice: it offers syntax highlighting and other features, and is extensively customizable. More information: listings package documentation.
  4. Another common choice is , which is also extremely powerful, using the library, but requires python-pygments, which you will have to install yourself. However, it has the most expressive syntax highlighting out of all of these choices. More information: minted on GitHub.

If your question concerns one of these packages specifically, please add the tag for that package as well. If your question concerns syntax highlighting specifically, you can also add the tag.

752 questions
30
votes
3 answers

Insert Bash code with coloration into my latex report

I am writing a long report, and I need to include some code I wrote. I would like my code to appear colorized, as can be seen in some text editors, but not by using the verbatim package. I need to colorize two distinct languages: Bash…
user23710
  • 1,491
25
votes
3 answers

LaTeX code for curly H used for Hausdorff dimension

Does anybody know the LaTeX Code for curly H used for Hausdorff dimension?
rich
  • 251
17
votes
2 answers

Python-like dictionary in latex?

Is there a command/macro in latex to generate python-like dictionaries, i.e. var = {a:1, b:2, c:3} which then return for \var{b} 2?
arc_lupus
  • 1,781
9
votes
1 answer

What is this code fragment for?

Taking a look at the code of the package ifxetex, I found the following: \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ProvidesPackage\endcsname\relax\else \ProvidesPackage{ifxetex} [2010/09/12 v0.6 Provides…
MickG
  • 5,426
8
votes
1 answer

How to make LaTeX code from the pdf file?

I am now on a project on translation a book from English to my native language. I always tried to do it as nearest to the orginal book as possible, and I used LaTeX for that. But my attempt failed, since I do not know much LaTeX to produce the same…
trequartista
  • 1,891
7
votes
3 answers

Triangle Notation in Spain

I have been told that the standard notation for a triangle in Spain is Does any one know how to produce the ABC with the wide triangle over it on LateX?
6
votes
2 answers

How can I add a little code block instream with text?

I would like to add a little code block in line with paragraph text. For example: In order to do this just run the [code block] command in your terminal. Can anybody help?
ajames
  • 215
5
votes
6 answers

How to mimic StackExchange-style inline code in LaTeX

I love the way StackExchange formats inline code, using both a fixed width font and a gray background. How can I mimic the above sentence in LaTeX? One possibility might be using a combination of the listings, helvet, and inconsolata packages (in…
Andrew
  • 1,249
5
votes
0 answers

Click to copy code snippets to clipboard in Latex-generated PDF

The Rust documentation has a wonderful feature where you can click an icon for the source code examples and it will copy it to the clipboard. Can this functionality be emulated in a LaTeX-generated PDF? Bonus question: A few of the example snippets…
user14717
  • 651
  • 4
  • 10
5
votes
1 answer

Copying code to LaTeX without losing the formatting

I have some code of around 350 lines, and I need to paste it inside a LaTeX file without losing the formatting such as the extra spaces. What do I need to use to get this in LaTeX?
Adam
  • 153
5
votes
1 answer

How to make my own LaTeX template?

Ok I know that my question is quite local, however, I have struggled with it for a long time and I could not find the answer, so I decided to post it here. I have to rewrite a book (which was written using Word) by LaTeX, without changing the…
trequartista
  • 1,891
4
votes
1 answer

Displaying an arrow underneath a symbol

This is probably easily answered, but how can I get this image in code? I have got something like this: \begin{gathered} A=(\circ, \bullet, \bullet).\\ \underset{\text { Position } 1}{\uparrow} \end{gathered} But I am not really satisfied with…
4
votes
1 answer

Adding programing code on LaTeX

I need to put some code from Linux's configuration files and some JavaScript in a document. I have tried to use \texttt, it worked for some Linux's basic commands like sudo apt-get install XYZ, but the code that I need to insert have # for comments…
lipesmile
  • 143
4
votes
1 answer

Changing ( and ) to \left( and \right)

Are there any plans to have the LaTeX automatically read all ( and ) to automatically become \left( and \right)? If so, then when can we expect the update?
3
votes
1 answer

Latin Extended: Latin Capital Letter A With Stroke

Latin Capital Letter O with Stroke is working but how about if I'm using another Letter like A, B, C to Z. \documentclass{article} \begin{document} {\O} %replacing the O with different letter is not working {\A} or {\Z} \end{document}
jeecabz
  • 1,448
1
2 3 4 5