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
0
votes
0answers
23 views

Using listinputlisting to include a specific (git) commit

I am discussing code which is in version control and would like to specify which version of the code to include. I did some research and found packages like gitlatex and gitinfo, but though useful, ...
2
votes
0answers
22 views

Setting color for numbers in code listing [duplicate]

I am trying to mimic the behavior of Gedit's code highlighting in listing. For example, Gedit makes all numbers (int, float) in Python pink, but I have trouble implementing this. I tried numberstyle ...
1
vote
1answer
26 views

Landscape view, two separate columns with listings over multiple pages

I want to compare two codes in two different languages in latex. I use lstlisting for both of them and then I want to see them side by side. I archived this using minipage environment but my listings ...
0
votes
0answers
29 views

\lstset colorize numbers in code [duplicate]

I defined a syntax highlighting for my code like so: \lstdefinelanguage{CSharp}{ sensitive = true, keywords={assembly, class, method, field}, keywords=[2]{public, private, family, ...
3
votes
1answer
61 views

TiKZ arrows and text inside of lslisting code

I have some lslistings code and I want to add some text and math elements as is shown in red color in the image below I tried using TiKZ but I got many errors. I'm attaching a MWE and thanks in ...
0
votes
0answers
50 views

Thesis turned NULL! [duplicate]

I was working on TexStudio and accidentally pulled out the plug, the PC turned off immediately (no battery). It happens regularly. However, this time when I restarted it and tried to open the .tex ...
5
votes
3answers
553 views

Single-key teletype?

I'm writing a document with a ton of pseudocode and it's very tedious to keep wrapping code objects in {\tt text}. It would be so much nicer to, well, do what StackExchange does! There's a one-...
1
vote
2answers
32 views

Problems when defining a general inline code command with listings or verb

I am trying to define an inline \code command (not language specific, just a smarter \texttt{} without the need to escape underscores or tildes, for example). I tried the three versions below based on ...
4
votes
4answers
541 views

How to illustrate the Mean Value theorem?

What packages can I use and what code to draw these functions?
0
votes
0answers
51 views

What's a nice way to display code in a document?

I'm looking for a nice or creative way to display code in a LaTeX document. I see a lot of nice layouts in books, with text-boxes, titles, annotations, delimiters, and all sorts of attractive things. ...
0
votes
2answers
24 views

lstinputlisting makes giant whitespace [closed]

I am using the Astronomy and Astrophysics template and want to add code at the bottom in a single column appendix. I have tried this by doing this. \onecolumn \appendix \section{Software use ...
1
vote
2answers
50 views

How to influence line breaks in lstlistings?

Latex breaks lines at odd positions in code listings, for example, before a comma or after opening quotation marks. Is there any way to influence the line breaking strategy or to suggest where a line ...
1
vote
0answers
81 views

Is there a LaTeX package for annotating text/code?

I would like to annotate one-line code (shell commands) in a LaTeX document. For example, the command du -ah --max-depth=1 . | sort -h. I like the style in which shell commands are annotated at ...
2
votes
0answers
56 views

How to change \lstinline{} font size? [duplicate]

I have the following example. I use \lstinline{} command to provide code within latex text. However the font size seems to be small. Please if you know how to to trigger this please let me know. ...
0
votes
1answer
37 views

Why I get opposite brackets at listing code?

I'm writing Hebrew document and the brackets at the code are opposite. They are ok at the regular mode but when I change the font style the brackets became opposite: And here is MWE: \...
0
votes
1answer
29 views

Insert a block of code as a paragraph

Looking to display several lines of code in my report as one block, the same way that code is displayed on Stack Exchange. For inline code I've been using \tikzhl and \texttt: \usepackage{tikz} \...
0
votes
0answers
34 views

How to create a code section with math symbols enabled?

I am trying to write some pseudo code with tex, so I wonder if there is a way to let tex follow my indentation while keep the tex commands. As I know, lstlisting will keep all the indentations and ...
5
votes
1answer
78 views

Listings color context sensitive keywords (Matlab)

In Matlab there's two ways to use end: to end ifs, whiles etc. to refer to the last item in an array/vector (example: v(end) or v(end-1)). I want to use listings to include some matlab code in my ...
1
vote
0answers
43 views

How can I hide (or blur) some code in a pythontex environment?

My question is directly related to this one. Does there exists a solution for pythontex ? At least for the verbatim environment. More precisely, let us consider the following MWE : \documentclass[...
0
votes
0answers
30 views

Post break hook Arrows not working on native mac LaTex Clients

I tend to use overleaf for most of my latex porjects, but recently have been forced to work on a local tex editor. I work a lot with R code and use the following settings on overleaf: \usepackage{...
0
votes
0answers
222 views

What does \fi means? [duplicate]

I want to know the meaning of \fi in LaTeX. I don't understand the use. And don't find an easy definition online.
1
vote
1answer
121 views

Execute code during beamer presentation

I am preparing a beamer presentation which includes demo of some C, C++ or similar code. As these are demo, the execution time is very little. I was wondering if it is possible to execute the code ...
1
vote
2answers
489 views

how to present python snippet code efficiently in latex

I am quiet new to Latex and do not know how to present a simple python code like this in Latex in a professional way.. having your solutions and examples will help me a lot to learn and progress. ...
0
votes
3answers
53 views

Inline environment shortcut (like $blah$)

I want to be able to format code with a monospaced font. Right now I'm using \texttt{} but it's kind of a pain to keep typing that everywhere. Is there any way to use a shortcut instead? For example, ...
1
vote
1answer
58 views

is there a package for schematic representation of Arduino?

i need to represent a circuit containing Arduino, i'm new to circuitikz and to latex, so i'm not able to code a complex circuit component.
1
vote
0answers
63 views

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 ...
1
vote
0answers
65 views

How can I highlight text in the middle of sentences [closed]

I want to be able to present short code in the middle of a sentence. How can I highlight text in the middle of sentences in Latex so it they appear as code. Consider this example For this purpose ...
4
votes
2answers
147 views

Hexadecimal line numbers in listings

Is it possible to introduce hexadecimal line numbers in steps of two using the listings package? In the MWE \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{...
1
vote
0answers
403 views

How can I beautify LaTeX code? [duplicate]

Is there any shortcut (or something else) that beautify the code, like ctrl+shift+f does in Eclipse or ctrl+k+d in Visual Studio?
1
vote
1answer
170 views

How to write inline code with semiverbatim in beamer

I use semiverbatim to write code block, now I want to use the same format to write inline code, how can I do this? \documentclass{beamer} \begin{document} \begin{frame}[fragile] \begin{...
7
votes
2answers
218 views

Two lstlistings side by side with refering arrow

SE I am trying to draw the image below in LaTeX using lstlisting, tikzpicture, minipage, and tabular The code that I got so far can be seen below \documentclass{article} \usepackage[utf8]{inputenc} ...
1
vote
1answer
82 views

Use code-style font

Just a quick question, I want parts of my document to be on this particular font which resembles a code, like this with mclust and FactoMineR: How can I do this?
1
vote
1answer
63 views

lstlisting - macro only for specific language

I am currently using following code for G-code formatting. Unfortunately I have no idea how do I enable the macro just for the new "gcode" language. \usepackage{xcolor} \usepackage{listings} \...
4
votes
1answer
95 views

How to type — or >> in minted?

If I try to type -- or >> (resp. <<), LaTeX puts them together and makes one big -, respectively guillemets. How can I change that behavior? I have to use LuaLaTeX to compile my source. \...
2
votes
1answer
61 views

Listing inside a frame using beamer

I want to use listing inside a frame. I know that I have to specify: begin{frame}[fragile] ..... However my code has not the row elements i.e. on the left the numbers related to the rows are ...
6
votes
2answers
104 views

Weird Vertical Spacing of '*' with Fira Code in Listings

I am recently getting started with LuaLaTeX and I was trying to set up a custom listings style for C++. Consider the following MWE: \documentclass{scrartcl} \usepackage{fontspec} \usepackage{xcolor} ...
1
vote
1answer
45 views

executable code containing symbol `^` inserted with verbatim on pdf. Error while copying back into a text editor

I'm trying to insert Octave code in a pdf containing the character ^. However when I copy the code from the generated pdf, the code doesn't run: The I already posted similar question and could solve ...
2
votes
1answer
113 views

Combine code and math mode

So i want to insert some line of codes in a formula like in the picture below. What is the best way to do this properly?
1
vote
1answer
191 views

How to produce colored code blocks in latex?

How can I write code block like this in Latex?
4
votes
0answers
74 views

Typesetting MAGMA code with minted?

I enjoy highlighting my Python code with minted. However I now would like to do the same with my Magma code (Magma is a commercial computer algebra system of broadly similar scope as GAP). However ...
0
votes
1answer
22 views

executable code containing symbol `'` inserted with verbatim on pdf. Error while copying back into a text editor

I'm trying to insert Octave code in a pdf. However, there is a problem with the sign ' (which means transposition in Octave code). However when I copy the code from the generated pdf, the code doesn't ...
1
vote
1answer
233 views

How to insert inline `code` in Lyx

I want to add an inline text formatted as code in Lyx. For example: "The gradient is calculated via math::gradient(v)" I am aware of the Insert List command, but it is not what I'm looking for since ...
1
vote
1answer
37 views

Code using verbatim doesn't work when copied back in a text editor

I'm trying to use verbatim to copy the implementation of an algorithm written in octave. For this I introduced the following lines in latex \begin{verbatim} F = @(z) [z(1) + 2*z(2) - 2; 2*z(2)*z(3)^2 ...
4
votes
1answer
57 views

Sinusoidal wire arrangements

I have to draw this one where we can see the one wire are of one color and the other are of other color joining at the square shape box, each wire has a name associate to it and then repeats(repeated ...
1
vote
1answer
105 views

Draw a figure (cut-off functions) in tikz

Please I need the code tikz for this figure. I have this code but it's not correct : [![\begin{figure} \begin{tikzpicture}\[x=1.5cm,y=1.5cm\] \draw\[thick\] plot\[domain=-100:40,samples=100\] ({3.5*...
1
vote
1answer
63 views

Changing font color in listing numbers

I want to change the font color in a listing. I want only several lines in the listing to change its color (e.g. 1, 2, 9, 10, 12, 13). That is, I want to apply the color to individual lines of the ...
4
votes
3answers
2k views

What font to use for source code in a document? [closed]

I'm currently writing some text where I discuss a python script. So naturally, there's a lot of code in the document and it seems like listings is the default way to do so. However, unlike what I'm ...
1
vote
2answers
28 views

How to include/mark code in the middle of the text line

I want to include short code for in a single line that is marked by a grey background. Here is an example: I want to include code of this form that is in the middle of the text.
3
votes
1answer
257 views

How do I set a background color and font for inline verb text?

I wish to customize the verb command such that I can customize the font and color, as well as set a rounded colored rectangle as background. I found this in the Tcolorbox manual: \DeclareTotalTCBox{\...
3
votes
1answer
569 views

Advanced customization of Minted code?

I'm a newbie to LaTeX, especially the minted package. I would like to customize it such that the code has a similar style to the attached screenshot. Specifically, I wish to be able to customize: The ...