Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
2answers
25 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 ...
3
votes
4answers
377 views

How to illustrate the Mean Value theorem?

What packages can I use and what code to draw these functions?
0
votes
0answers
42 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
23 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
49 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
47 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 ...
3
votes
0answers
30 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
36 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
27 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
71 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
39 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
29 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
89 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
105 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
307 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
51 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
50 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
48 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
58 views

How can I highlight text in the middle of sentences

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
131 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
228 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
121 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
193 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
60 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
53 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
87 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
53 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
100 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
43 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
78 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?
2
votes
1answer
147 views

How to produce colored code blocks in latex?

How can I write code block like this in Latex?
5
votes
0answers
57 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
180 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
36 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 ...
5
votes
1answer
55 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
95 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
60 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
25 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
244 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{\...
4
votes
1answer
461 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 ...
3
votes
1answer
88 views

Use `code` syntax to insert some code [duplicate]

Instead of using \usepackage{listings} ... lstinline{for} or \lstinline{while} or \lstinline{main} Here you \codeword{see} an \codeword{example} of \codeword{code} how is it possible to define this ...
0
votes
1answer
110 views

Escaping HEX-characters source code in \lstinputlisting

I am currently writing a paper where I need to put full Python source code files into the appendix. Since I do not want to bloat my TeX file, I include source code with \lstinputlisting. The source ...
1
vote
1answer
43 views

Highlighting Java Code like Bitcoin Whitepaper

In Bitcoin Whitepaper ( https://bitcoin.org/bitcoin.pdf ) on page 7, there is a C code snippet. The style, font and the size is very neat and proper. How can I apply this kind of style for my java ...
0
votes
1answer
167 views

How to write a block of a real code (and not pseudo-code) in Latex?

I want to write the following code in latex, such that in pdf, we see the same format of writing (except background color and font colors). However, by algorithmic, output format is different. Is ...
0
votes
0answers
42 views

Add bibliography with usepackage{biblatex}+addbibresource+printbibliography: not working in Texmaker, working in ShareLatex [duplicate]

I wrote the code: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{biblatex} \addbibresource{bibliografia.bib} \title{\textbf{Template}} \date{\vspace{-10ex}} \begin{document} \...
0
votes
1answer
522 views

Bibliography does not appear - BibTex

I read a lot of posts about this topic (Question mark or bold citation key instead of citation number, Latex references and bibliography not working etc), but they don't meet the needs. I followed the ...
0
votes
0answers
122 views

Using of \null command alone [duplicate]

I'm trying to understand what is the purpose of \null command. To do this I wrote the code: \documentclass[11pt]{article} \begin{document} Ciao ciao \null \null \null \null ciao ciao \end{document} ...