Skip to main content

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
11 votes
3 answers
2k views

How to Draw Gabriel's Horn

Consider Gabriel's Horn: which, mathematically speaking, is the curve y=1/x over the interval [1,∞] revolved about the x-axis. It is interesting because though it contains a finite volume, its ...
DDS's user avatar
  • 9,768
0 votes
0 answers
35 views

Lyx creating too much space in in-line code before maths symbols

I use code in Lyx documents (Text Style -> Code). I need to enable Logical Markup to enable this. In-line code works fine usually but with unusual characters like ℕ, the output seems to create too ...
Penelope's user avatar
  • 217
3 votes
1 answer
147 views

How to format code in the style used in academic papers?

I came across a scientific article that features beautifully formatted code, as shown in the image below. I'm interested in using a similar style for my own article, but I'm not sure how to achieve ...
drobilc's user avatar
  • 161
3 votes
2 answers
125 views

Bug with colors when trying to paste C++ code into LaTeX [duplicate]

I have already dealt with a similar problem, that I can’t make the colors in the Text work properly! Now I've switched to the code and made other settings so that they don't conflict, but I'm getting ...
Dmitry's user avatar
  • 145
-3 votes
1 answer
75 views

Simple Question [closed]

How to write the image below in latex?:
muzan muzan's user avatar
1 vote
1 answer
18 views

Unwanted indent in lstlisting [duplicate]

I am using listings to explain pieces of a code, but the PDF adds unwanted indentation. How to remove it? Here is a MWE: \documentclass[12pt, twoside, openrigt, a4paper]{memoir} \usepackage{xcolor} \...
Brasil's user avatar
  • 1,380
1 vote
0 answers
26 views

Lstlisting doesn't highlight keyword

I have the MWE below. However, the keyword \getit is not highlighted. How to turn it blue? \documentclass[12pt]{memoir} \usepackage{xcolor} \usepackage{listings} \lstset{ basicstyle=\...
Brasil's user avatar
  • 1,380
0 votes
2 answers
61 views

normal probability density function

I want the function visualization as the picture but my code have issue that I dont know how to fix: \begin{align*} f(x) &= \frac{1} {sigma}{\sqrt{ 2 \pi } \e ^ -\frac{ 1/2}\biggl(\frac{ x - \...
Annie's user avatar
  • 3
3 votes
1 answer
35 views

Code shows in Greek letters

I have been trying to insert an Octave function in my paper but when I build the pdf the letters are all turned into greek.(The rest of the paper is written in greek). What is even weirder is that ...
I Like Algebra's user avatar
0 votes
0 answers
32 views

Highlight text that contains some citation [duplicate]

I'm trying to add some new citations in my article. Im using the following command: "some citations in this fields are \hl{e.g., \cite{abc2020}, \cite{def2021}, among others}." However, the ...
top north 5088's user avatar
0 votes
1 answer
54 views

Highlighting on lists of strings and lists of numbers in a listing

I am following the format used by this answer to color a json listing on my document, but I noticed that in a list of strings and a list of numbers, only the first element gets colored properly. Is ...
nottelling's user avatar
1 vote
0 answers
60 views

Coloring functions, methods and attributes automatically in lstlisting

I am currently working on some materials for my CS classes and since I work in VSCode my goal would be being able to reproduce the color theme used in VSCode faithfully in LaTeX. For that I have ...
b00n heT's user avatar
  • 166
1 vote
0 answers
87 views

tcolorbox locally change color of text in a code block

I've been working with \tcolorbox for a bit to get the desired output of my code blocks, see below for an example: and code: \documentclass[12pt]{report} \usepackage[letterpaper,margin=1in]{geometry}...
Matteo's user avatar
  • 323
0 votes
0 answers
56 views

unknown issue with tcolorbox bash code

Hi there I've been recently, thanks to the help received in this post, updated all my code blocks to a much nicer and neat view using tcolorbox. Unfortunately, for some reason, two of them show the ...
Matteo's user avatar
  • 323
3 votes
2 answers
312 views

Writing Mathematica code in latex

I am trying to type the following Mathematica code e[a_, -1] := (1 - 2^(-a)) Zeta[a] in Latex file using \texttt{....} but the file didnt compile. But when I ignored the signs ( ^ , _ ), the file ...
Ali Shadhar's user avatar
0 votes
1 answer
28 views

How to display two screen sessions in palallel?

I'm trying to produce something like the following in LaTeX - just the general layout, illustrating the flow of communication between two command line sessions: I have tried variations over: \...
j4nd3r53n's user avatar
  • 509
1 vote
0 answers
44 views

Inserting code environment in an endnote

I am currently writing a report in which I have to include many bits of code in endnotes on a different page. Doing every reference manually seems unnecessarily tedious. I found a way to insert python ...
Galou's user avatar
  • 33
0 votes
2 answers
73 views

Combine two codes of codehigh

I'm having a hard time trying to have one code giving the full code and its output, side by side. Please help. Thank you. \documentclass{article} \usepackage{codehigh} \usepackage{amsmath} \...
Rafiq's user avatar
  • 255
1 vote
1 answer
110 views

Python code in two-column document

I want to put my python code in a two-column document. I am using the listings package with the following preamble: \usepackage{listings} \usepackage{xcolor} \definecolor{codegreen}{rgb}{0,0.6,0} \...
curious_direwolf's user avatar
0 votes
1 answer
38 views

Help with bar chart

I need to make a graph similar to the photo. I have the beginning of the code in LATEX, but it does not work correctly, you also need to add inscriptions like in the photo, you can write in your own ...
benderrr's user avatar
0 votes
2 answers
81 views

Help to complete the graph in Latex using tikz

I would like to ask for help in building a graph, I really need your help My code: \documentclass[tikz,border=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{angles,quotes} \begin{document} \...
benderrr's user avatar
1 vote
2 answers
41 views

Set code font style for words in table

MVP: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{lmodern} \usepackage{color} \usepackage{tcolorbox} \usepackage{float} % Better figure and table ...
Alix Blaine's user avatar
0 votes
1 answer
33 views

Coloured subsection AND text right after the subsection name

I'm facing a problem due to the incompatibility between the packages TITLESEC and SECTSTY. What I want is to have a coloured subsection name, which I provided with \usepackage{sectsty} \subsectionfont{...
Henry's user avatar
  • 402
5 votes
6 answers
630 views

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 ...
Andrew's user avatar
  • 1,269
0 votes
1 answer
64 views

how can a reproduce a code snippet that looks tabular

Here is the image I cropped from an article. I would like to know how to reproduce the overall structure of this code snippet.
Mosh Geb's user avatar
1 vote
1 answer
231 views

Custom language lexer alias not found by pygments for minted

Problem I've made a custom lexer for a pseudocode language in Python (3.11). The file is saved in the same directory as my TeX project. I am using pdflatex to compile my project, and it has the --...
BrightBulb123's user avatar
0 votes
0 answers
146 views

How to render a PDF with selectable indentation whitespace for a code block?

I'm trying to create a PDF that will contain code snippets, and since they will mostly be in Python, the indentation is important. I found the fancyvrb package, which looks great in the PDF, but my ...
vee's user avatar
  • 1
2 votes
1 answer
104 views

Plot a sequence to show the limit, improving the code

I wanted to generate a good figure to show the visual definition for the limit of a sequence. This is an idea so far, but I would like to improve it, for example: How can I delete the thicks on the $...
Henry's user avatar
  • 402
1 vote
1 answer
84 views

Change color to all items in enumerate: only the "indicator"

I don't know the right terminology, but what I am looking for is this: say I write \begin{enumerate}[(1)] \setcounter{enumi}{-1} \item blabla \item $x - 3 = 0 \iff x = 3$ \item The End. \end{enumerate}...
Henry's user avatar
  • 402
6 votes
2 answers
341 views

LaTeX3 - Advice on a code to validate an ISO date

The following code is a POC showing a way to validate one Julian date in "pure" LaTeX3: it is related to this question. There is no doubt that this code contains some clumsiness. Any advice ...
projetmbc's user avatar
  • 13.4k
0 votes
0 answers
36 views

New Install Problem (TeXShop)

I just bought a new Mac. So I downloaded TeXShop and tried to typeset a test file. I got this error: xelatex: Command not found. Is there something wrong with in my preface? Yes, I'm sure there's ...
Epimanes's user avatar
  • 111
1 vote
0 answers
33 views

Caption alignment issues with lstlistings environment inside lists

The alignment of the caption of the my lstlistings environment for code is not correct when inside lists. The code to generate the image is given in the working example... \documentclass{article} \...
user41177's user avatar
  • 375
0 votes
1 answer
82 views

How can I restyle the listings caption to a tcblistings environment?

I am trying to define a tcblistings environment that should work under the following syntax... \begin{code}{TITLE}{LANG}{CAPTION}{OPTS} code here \end{code} Everything but the language should be ...
user41177's user avatar
  • 375
0 votes
0 answers
22 views

How to load keywords from two languages in lstlisting? [duplicate]

I know how to define two different styles for two different languages in lstlisting package. I want to include keywords from Lua as well as LaTeX in the same style. Is it possible? \lstdefinestyle{...
user61681's user avatar
  • 1,769
2 votes
1 answer
88 views

How to get the QED symbol without using the proof environment

I want to get the QED symbol at the right end of the proof without using the proof environment and I want the QED symbol inside \begin{itemize}... \end{\itemize} environment. Is it possible? Thanks ...
Ali Shadhar's user avatar
1 vote
0 answers
71 views

Wrapping inserted code from MATLAB

I am attempting to insert a very long code that I wrote in MATLAB into my thesis document written on Overleaf. Several of the lines have long equations or comments that extend beyond the page and I ...
Jah's user avatar
  • 11
1 vote
2 answers
72 views

Why are my theorems not numbered by letters?

I'm trying to enumerate the main theorems from my paper using letters instead of numbers. I've tried using the following code but it's not working (at least the counter is!) \documentclass[11pt]{...
Marra's user avatar
  • 225
11 votes
2 answers
762 views

Replicating a chronodex in TikZ

I've tried to make a chronodex in TikZ and I have a basic skeleton. I need to add a few more things to it (ticks, labels, nodes). Besides, the code itself could be optimised using loops but I'm still ...
crypto's user avatar
  • 757
0 votes
2 answers
94 views

How do you use minted to render a code block in monospaced font with all black text?

How do you use minted to render a code block in teletype font (monospace fixed width font) and all text is the same color (probably black)? What would you write if you wanted all text to be black ...
IdleCustard's user avatar
  • 1,250
0 votes
0 answers
17 views

Hiding extra string space in pdf document by using latex - overleaf [duplicate]

I am trying to type Python code by using LaTeX. The code is not being formatted properly Example: #PDF var = function(data, parameter= 'compile') #Copy it on my terminal var = function(data, ...
Lola's user avatar
  • 1
-2 votes
3 answers
133 views

How can I draw top right corner trimmed rectangle in tikz? [duplicate]

If possible I want to draw a code figure (looks like rectangle but right-top corner is trimmed) in tikz. Basic sample would be: ____ | \ |< >| |___| Is there any sample for this? Original ...
alper's user avatar
  • 1,505
0 votes
0 answers
20 views

How can minted (or something similar) work with automatic alignment of code? [duplicate]

I typeset Lisp code in a proportional typeface, and it relies on alignment. An example of the typesetting can be seen here: If I ignore font selection, it was typeset using this code: \begin{tabbing} ...
matj1's user avatar
  • 119
1 vote
1 answer
125 views

Continue code on the next page with line numbering (minted, tcolorbox)

Here is my code: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{listings} \usepackage{minted} \usepackage{xcolor} \usepackage{tcolorbox} \tcbuselibrary{listings, minted, skins} \tcbset{...
WinnieNotThePooh's user avatar
0 votes
1 answer
240 views

How can I export a txt table to latex? [duplicate]

I have txt file with table format, I did it in python but now I have to export this table to Latex but I don't know how. I'm not good at all in latex so I'll appreciate if you help me. Thank you!
Hache 99's user avatar
0 votes
0 answers
268 views

Modifying existing Latex code to put Python codes in the Cheatsheet

I want to make a cheatsheet for Pandas which has Python codes. I googled and tried to find a free online site that help to get built easily. I'm unable to find except overleaf which uses Latex codes ...
Mithlesh Upadhyay's user avatar
0 votes
0 answers
65 views

How can I align code listing with a propotional font?

I'd like to typeset some code with a proportional code with alignment. How can I do it? The capabilities of listings to align are limited, and I was using tabbing, but it causes problems because every ...
matj1's user avatar
  • 119
0 votes
1 answer
50 views

Best way to indicate that some lines are left out

Assume I wrote a class myclass in Matlab with many properties and methods, and now I want to display its most important properties (foo and bar), the headers of its most important methods (myclass ...
Οὖτις's user avatar
  • 2,927
1 vote
0 answers
62 views

Words going off the page, why?

I'm using LaTeX to turn in a school assignment which contains code snippets. The code snippets themselves look visually appealing, but the text unfortunately goes off the page if there's too much code ...
Anish G.'s user avatar
0 votes
1 answer
83 views

Minted: colorize variable in inline mode

Is it possible to specify how to color a variable with mintinline? What I mean is, for instance, to use \mintinline{python}{myClass} and color myClass as a Class variable, or as a function. If I use ...
PerroNoob's user avatar
  • 641
1 vote
1 answer
151 views

Use lmodern package for minted code and palatino package for the rest of the report

I am writing a technical report and I need to use the palatino package for it. However, the minted code font is not very legible since it doesn't use deep black but slight gray instead. Hence I want ...
yolo_ML's user avatar
  • 11

1
2 3 4 5
16