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.

Filter by
Sorted by
Tagged with
1
vote
1answer
28 views

How to insert (C/C++) code into my document with a grey background?

I am using the listings package to insert code from files into my .tex document like shown here - https://stackoverflow.com/a/21344989/4647107 I have instances in my .tex document where I am inserting ...
0
votes
0answers
21 views

Minted listings spanning across multiple pages with caption

I'm using the lncs class and I'm trying to have long code highlighted with minted to span across multiple pages with a caption. According to the minted documentation, a new environment is needed. I'm ...
0
votes
0answers
13 views

Overwrite listing style

I want to add some code in a listing with syntax highlighting. But for this language I like to change the style so the keywords are not blue like they normally are but bold and black. In addition when ...
0
votes
2answers
35 views

How to put a list of code in appendix?

I want to put a code in my thesis appendix. print('This sentence is output to the screen') # Output: This sentence is output to the screen a = 5 print('The value of a is', a) # Output: The value of ...
1
vote
2answers
29 views

give a document input to lstnewenvironment

I recently asked this question: Independent caption and numbers on different lstlisting language script And the answer for my need was to use \lstnewenvironment. Problem is that I'm still working on ...
0
votes
1answer
24 views

Independent caption and numbers on different lstlisting language script

I'm trying to write a document where I use AMPL, Python and I would also like to be able to show some of the outputs. Problem is that the first python code is Script 1, the first AMPL is script 2, ...
0
votes
0answers
24 views

Minted: won't break page

This is example of my problem. This picture shows the end of the page This is my code begin{listing}[ht!] \begin{minted} [style=colorful, breaklines=true] {java} //code... public class Document { ...
2
votes
1answer
50 views

\texttt causes problems with quotes and angled brackets ("<)

In my LaTeX source-code I need to emphasize some terminal commands. For that I use \texttt. This worked fine for most commands, but some special characters cause problems: myapp --url "<webserver-...
1
vote
0answers
18 views

Apply specific color to !important in CSS using listings

Problem: I wish to apply a gray color to !important in CSS when using listings. I have managed to modify so that the color is different after : but how can I modify the code below so only !important ...
0
votes
2answers
55 views

How to insert math symbols as text in Latex without getting error messages

How can I insert [1+(-1)^n/n, {n, 10}] (text as it is) in latex without getting any error messages like missing $ (latex interprets this as an equation), or missing \ , for the brackets { I have ...
3
votes
1answer
39 views

Highlighted code inline

I would like to write some code inline with other text. The code should match other code I write in the document though. So it should be highlighted (let's say yellow), should be in typewriter font ...
0
votes
0answers
22 views

How to copy code chunk containing unicode character in verbatim environment? [duplicate]

In Julia programming language, one can type Unicode character such as If I want to copy paste a chunk of code in a tex file. What should I do? Here is an unsuccessfule attempt: \documentclass[...
0
votes
1answer
43 views

Formatting Matlab file with lstlisting

I included a Matlab file, and it worked fine. The colors changed and it looked nice. Suddenly Latex doesn't change the colors of the code, except of the background color. Is something wrong with my ...
0
votes
2answers
43 views

Purpose of comment sign around figure and table

In many Latex docs, I see people do: This is an example paragraph... blah...blah... % \begin{figure} ... \end{figure} % and then blah...blah... I'm confused, what is the purpose of % before and ...
0
votes
0answers
51 views

How to show exactly what I type

I want to put code of my calculation in computer algebra systems in my PDF file. If I just paste the code in the .tex file, it does not get shown correctly in the PDF file: I would need to change x^32 ...
0
votes
0answers
31 views

pandoc *.md to *.pdf with code block that keeps spaces/tabs

I'm using the following command line to generate a *.pdf file from my *.md file: pandoc --pdf-engine=xelatex file.md -o file.pdf Everything works fine except when I copy-paste a code block from the ...
5
votes
1answer
112 views

How to highlight numbers only outside a string in lstlisting?

I have some source code in Python and I would like to highlight numbers, but only if the number is part of an operation or in a declaration, that is, if I name a variable variable1 for example, I don'...
0
votes
0answers
26 views

Why lstlisting does not highlight numbers?

I would like to include some python code in my document, and here is what I have written so far: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{graphicx} \usepackage{amsmath} \...
0
votes
0answers
29 views

minted linebreak in framebox

I have a code snippet that I highlight with minted. The problem is that one line is too long, and goes out of the frame box. \begin{figure}[H] \begin{minted}[ frame=single, ...
1
vote
1answer
44 views

Spaces Before and After Slashes

For example, a space after \hfill does not add a space to an output. LEFT\hfill{}RIGHT LEFT\hfill RIGHT If I put another space in front of \hfill, then will this space change the output adding an ...
1
vote
0answers
43 views

How to make sure the name for a custom macro is unique and won't result in a clash?

When a new macro is created (typically with \newcommand, \renewcommand or \newenvironment), it requires the user to come up with a name and a definition. The name should only consist of letters (or ...
0
votes
0answers
43 views

Latex create a function to wrap code

I have the following to highlight code: \begin{minted}{python} def foo(): \end{minted} However, typing out \begin{minted}{python} is quite tedious. I want to convert it something like the ...
1
vote
0answers
14 views

Listings: make range delimiters white, and hide block comments

Simply put, I'd like my range delimiters to be white so that they do not appear if I show a block of code. I would also like to omit certain block comments entirely. I've read the listings manual and ...
0
votes
1answer
51 views

How to define a custom command in minted environment

I am new to Latex so I might be missing something basic. I need a custom command for code snippets. Normally I would write this: \begin{minted} [ frame=lines, firstnumber=182, framesep=2mm, ...
0
votes
0answers
38 views

Copyable code blocks in LaTeX using verbatim or lstlisting

I tried to copy code blocks from the compiled pdf using the following code I used pdflatex to compile it. If I used 3 lines of code, copying worked as expected, I got back the same arrangement as the ...
2
votes
2answers
121 views

Where is the error in my LaTeX codes?

I use rogercortesi.com to convert LaTeX codes into images. But the code I wrote below doesn't work. I couldn't understand why. But the same code works very well here. What is the cause of the problem? ...
2
votes
1answer
45 views

Change size of Python code in LaTeX document

I am trying to input my Python code in a document using this template which uses the listings package. However I want to change the size of the code font i.e. any mentions of \texttt{} and the ...
0
votes
0answers
26 views

Target specific elements in listings and format to CSS

Problem: I wish to target the elements <style>and </style> so that listings would format the content between these two elements as CSS. I have managed to format it separately, but I wish ...
3
votes
1answer
88 views

tcbuselibrary: redefining “every listing line”

This is following up to an earlier question: Drawing Realistic Linux Command Shell Windows with tcolorbox I'd like to be able to create something like this: For the most part I can, but I ...
0
votes
1answer
43 views

Box-drawing characters cause error - Package inputenc: Invalid UTF-8 byte sequence

I have a code snippet wrapped inside a listings: \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting} printf("┏━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓\n"); printf("┣━━━━━━━╋━━━━...
18
votes
1answer
659 views

Drawing Realistic Linux Command Shell Windows with tcolorbox

I'm trying to make these little imitation command shell window/box/things. The problem is I can't skip lines. The prompt (aka. $PS1) appears on every line; there's no room for the command output. Any ...
1
vote
1answer
44 views

minted and tcolorbox: putting code in the title

I suppose it's meant to be used like this: But sometimes I like to use the title section to represent code or a command or some kind of input, and show the output in the bottom section like this: ...
1
vote
0answers
26 views

Special characters in formatted code [duplicate]

I want to show some nicely formatted source code, e.g.: er ist ein bisschen ein ötto geworden My document: \documentclass[a4paper,10pt,ngerman]{scrartcl} \usepackage{babel} \usepackage[T1]{fontenc} ...
0
votes
0answers
24 views

Tabular With Code - “<” and “>” Are Not Recognized [duplicate]

This table \begin{tabular}{ | l | l | } \hline Ausdruck & Wert \\ \hline int x = 49; & -- \\ \hline !(x >= 0 \&\& x < 50 || x > 50 \&\& x <= 100) & true \\ \...
0
votes
0answers
9 views

Code folding in kile does not work properly when there is a {eqnarray} or a {gather} or a {align} in the block

I'm running Kile 2.9.92 as LaTeX editor on Windows 10. I'm currently writing a beamer presentation with several frame environments. In order to easily navigate through my code I'm using the "code ...
2
votes
1answer
42 views

How to refer to line numbers of source code in listings without adding labels by hand?

I use listings to produce my Matlab code. There I can use the \label and \ref commands for readers to direct them to my code and line number. \begin{lstlisting}[caption={Code for deflection at the ...
4
votes
2answers
61 views

How to pass text with # in the beginning to a macro (minted)?

I created a command to input code in my document with minted. \documentclass{scrartcl} \usepackage{minted} \newcommand{\inlinecode}[2][text]{% \mintinline{#1}{#2}% } \begin{document}% ...
2
votes
1answer
46 views

Listings - Hide range labels and suffix/prefix from code

I'm using listings to generate some code boxes, and am taking excerpts using range labels with suffixes and prefixes. I'm able to hide the begging tag from the full code by escaping to LaTeX and using ...
1
vote
2answers
46 views

color curly braces in listing

I want to change the color of some part of the code in listing. Here is the MWE I have tried: \lstdefinestyle{mystyle} {escapechar=\%} \lstset{style=mystyle} \lstinputlisting{Pro/Code.java} Inside ...
1
vote
1answer
68 views

How to write code as normal text?

I got an assignment where i have to explain some code and to do that i have to show my code as normal text. I have no idea how to show my code so is there anyone that could show me how it's done? \...
0
votes
0answers
39 views

Code in latex for document of non latin alphabet

I need to include a code in a document written in greek. I found the command to include the code as it is written, but the letters appear with the greek alphabet in the compiled version. Does anybody ...
0
votes
0answers
29 views

Reliably use \overline in minted code

How can I (reliably) use \overline in minted code? For example, these work: \documentclass{article} \usepackage{newpxtext} \usepackage{newpxmath} \usepackage{minted} \newmintinline{ocaml}{...
1
vote
0answers
13 views

How change the label “Listing” into “Code”? [duplicate]

I'm new with LaTeX and now I have a problem with a reference of the C++ code. I have this code: \begin{lstlisting}[label={code:enumtx}, caption={Porzione di codice che riporta il tipo enumerazione ...
1
vote
1answer
73 views

How to include a highlighted source code from external tex file?

I have tried to minimise my scenario here. Basically, I would like to call each piece of highlighted code from external tex file over the beamer class. There are two .tex files code.tex main.tex ...
1
vote
2answers
146 views

How to highlight code inside verbatim environment?

I am writing a book containing tutorials and I need to show code: Write this: \begin{verbatim} function doit() { console.log("Hello"); } \end{verbatim} And then add these lines: \begin{verbatim}...
0
votes
0answers
47 views

what is the code if I want to say that x is an element of the real number system in LaTeX using notation?

what is the code if I want to say that x is an element of the real number system in LaTeX using notation.
3
votes
1answer
142 views

Format code correctly in LaTeX

I am pasting some code I have developed for a project from Visual Studio 2019 to LaTeX for a report, however upon pasting the horizontal spacing is far too large and runs off the page. Currently I am ...
0
votes
1answer
35 views

Mint code inline reading from file

Is there a way to mint a line of code inline, where the code is read from a file? \mintinline can only typeset code that is passed directly to the command, in between two delimiters (e.g. \mintinline{...
3
votes
2answers
74 views

Command to display and execute code (math formulae)

Similar to New command to display a symbol and its command I would like to have a command to display and execute code. The code should be displayed with the listings package. For example something ...
0
votes
0answers
22 views

break colorbox in lines for lstset inline code

I use this latex code to define icode commadn with which I can write inline codes: \definecolor{lightgray}{gray}{0.9} \lstset { frame=shadowbox, rulecolor=\color{white!80!black}, ...

1 2 3 4 5 11