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
0 answers
30 views

Integrate Python code into Latex

Hi I would like to display a code with Minted. I have written the following \documentclass[11pt]{article} \usepackage{minted} \usemintedstyle{fruity} \begin{document} \begin{minted}{python} import ...
user avatar
  • 1
0 votes
0 answers
57 views

Can I type LaTeX code in inkscape without a locally installed LaTeX distribution?

I use Inkscape 1.1 and I need to type LaTeX code (formulas and text in general) but I do not have a LaTeX distribution installed on my machine (I use Overleaf, online LaTex editor). Example: if I type ...
user avatar
  • 491
2 votes
3 answers
93 views

Right triangle with angle

So my problem is simple, I just want to create a right triangle with angle 18. What I have so far is Here's my code: [asy] size(300); pair A = (0,0); path B = dir(18); path C = dir(90); draw(A--B--C--...
user avatar
0 votes
0 answers
19 views

Package CJK Error: Invalid character code

Today, I use another computer to run my .tex. The console shows the following error. But, I can run the same file on my foemer PC. After diagnosing, I find the problem which is marked below. If I ...
user avatar
0 votes
1 answer
36 views

Blank space after equal-sign in Python-Code-Section of LaTeX-Dokument-PDF by using packages "listings" and "pythonhighlight"

Does anybody know how to set the packages "listings" and "pythonhighlight" for displaying one blank space before (this already works) and after an "=" (and maybe other ...
user avatar
  • 3
0 votes
0 answers
58 views

How to write Octave code on LaTeX?

Here is an exemple of code I would like to write: clear all; close all; clc; X = Y = 0:0.1:1; for i=1:length(X) for j=1:length(Y) Z(i, j) = X(i) + Y(j); endfor endfor mesh(Y, X, Z) The ...
user avatar
0 votes
0 answers
47 views

How to indent minted code blocks?

I'm using org-mode to generate the pdf and set the code backend to minted. The org source is shown as below: Some text. #+begin_src c #include <stdio.h> int main() { printf("Hello, ...
user avatar
1 vote
0 answers
33 views

Understanding how to apply different colors in chemfig

In the answer to this post, Symbol 1 (the answerer's nick) generated the following chemical figure with different colors using the code below. \documentclass{article} \usepackage{chemfig} \begin{...
user avatar
  • 1,174
0 votes
0 answers
31 views

Unable to view source code in texstudio latex

I am using Texstudio 4.2.2. I write my source code and compile it successfully and view it many times as PDF. After a few days, I got my paper revision. When I open the text studio my source code only ...
user avatar
  • 1
0 votes
0 answers
49 views

Markdown -> Latex -> PDF: md inline code snippets going out of page bounds

Problem I have a bunch of changelog.md files for our software that use backticks for inline code. I pull them as part of the documentation build process and compile a PDF with latex. Latex seems ...
user avatar
  • 75
4 votes
4 answers
181 views

Help with a figure with absolute value

I am trying to draw $y=|x|^{1/2}$ on LaTeX, but I have no idea how to do it. I tried to use this code \begin{tikzpicture} \begin{axis}[% domain = -3:3, samples = ...
user avatar
  • 43
1 vote
1 answer
22 views

How to create a code block with boxed title at top (see image)?

How do I create something that look like this? (Taken from FEniCS Tutorial book pdf page 14 (actual 6)) It doesn't have a caption or table/figure tag near it.
user avatar
0 votes
0 answers
25 views

What's the best way to deal with large pieces of text like keywords, camel cased words, namespaces, etc [duplicate]

I'm writing a text which has a lot of long Redis keys and camel cased text (like class names). This could be extended to long keywords and namespaces too. I want to accentuate these in way, so I'm ...
user avatar
  • 539
1 vote
0 answers
26 views

how does the nested \def in \def\inst{\beamer@insttitle}\def\and{\beamer@andtitle}

I am trying to understand the following code: \def\author{\@dblarg\beamer@author} \long\def\beamer@author[#1]#2{% \def\insertauthor{\def\inst{\beamer@insttitle}\def\and{\beamer@andtitle}#2}% } ...
user avatar
0 votes
1 answer
71 views

Want to style LaTex code, in my lstlistings

in the manual of the command of the listing package, "LaTex" is one of the predefined languages. I know it may sounds confusing but I want to write my Latex code with the \ and everything (...
user avatar
  • 3
0 votes
1 answer
178 views

How to add code in overleaf

I have to copy-paste some code in an overleaf document. But the code has tons of percentage symbols that overleaf takes as comments. I wanted to ask if there is any way I can just paste the code as it ...
user avatar
  • 115
0 votes
0 answers
32 views

Is there a LaTeX package which helps me get code listing with notes?

I want to display some notes beside my code like this.
user avatar
  • 1
1 vote
0 answers
41 views

How to include code in Latex so it can be copied from pdf file to editor?

I am wondering if there is a way to include code samples in a Latex document, such that the code can easily be copied from the exported pdf into a code editor? I am using Latex in Gummi on Linux and I ...
user avatar
  • 111
0 votes
0 answers
32 views

A multi-page Matlab code in Lyx

I recommend using matlab-prettifier package (see https://tex.stackexchange.com/a/158816/586), which only provides a style for the listing package. This will give you a good highlighting of Matlab code....
user avatar
0 votes
0 answers
37 views

How can I make all the text in this overleaf template black?

I have a query, I want all the text of this overleaf template to be black and I can't find the line of code that puts all the words in black when I put it. no line I put does anything. any ideas? ...
user avatar
  • 1
0 votes
0 answers
46 views

How to evaluate latex code in markdown (pandoc) code chunk?

I wan't to evaluate latex command \input{file} in code section in pandoc markdown. I tried this: ```matlab syms s; G = \input{"raw.txt"}; step(G); ``` file raw.txt contains this: (100*s + ...
user avatar
  • 3
0 votes
0 answers
68 views

How to make a personalised ruler?

I wanted to know if and how would it be possible to create a personalised ruler in LaTeX. "Personalised" means I would like to create something like the "famous" IMPERFECTO ruler, ...
user avatar
  • 308
1 vote
0 answers
17 views

Apostrophe in codeblock [duplicate]

Hello I was trying to put '\n' on codeblock, and I have just realized that my apostrophe is in weird direction when in codeblock I wanted something like The code was \documentclass{report} \...
user avatar
  • 123
0 votes
1 answer
49 views

codeblock colors

Hello this is the codeblock code I currently use \lstset{ backgroundcolor=\color{gray!10}, basicstyle=\ttfamily, columns=fullflexible, breakatwhitespace=false, breaklines=true, ...
user avatar
  • 123
2 votes
1 answer
74 views

Writing in Greek, but can't copy Greek?

So, I have a file in Gree, with some English letters. Everything works fine, no syntactic errors or anything. When I go into the PDF to copy from it or search for something, it never returns my query. ...
user avatar
0 votes
0 answers
32 views

Whitespace rendering + selectable indentation spaces for python/yaml/etc code snippets

I have three related issues here and I wonder, which approaches/libraries/built-in utilities may help me achieve the following: First There are many programming languages and file formats which depend ...
user avatar
  • 11
1 vote
1 answer
36 views

Listing for file folder-structure as text not working

For my documentation, I need to provide a way on how to structure some Python code in a project. My approach to show it was to simply use a structure of text like this: app/ ├─ ... ├─ controllers/ │ ├...
user avatar
  • 151
2 votes
1 answer
84 views

How to put underscore and & in codeblock

Hello how do I put _ and & in codeblock? \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{float} \usepackage{amsmath} \usepackage[a4paper,margin=1in,footskip=0.25in]{...
user avatar
  • 123
2 votes
1 answer
52 views

Highlight source code keeping spacing intact

I try to highlight some lines of a code using colorbox in listings. \documentclass[12pt,a4paper]{report} \usepackage{xcolor} \usepackage{listings} \begin{document} \lstdefinestyle{data}{ ...
user avatar
  • 498
1 vote
1 answer
50 views

minted: How to change the start number for numering lines?

When you use \begin{minted}[linenos], it numbers the lines starting at 1, ie: 1 console.log('something') 2 console.log('another thing) ... What should I do to start the numbering on any number, say, ...
user avatar
  • 13
1 vote
1 answer
60 views

How to put subscript on code block

Hello how do I put subscript in code block? \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{float} \usepackage{amsmath} \usepackage[a4paper,margin=1in,footskip=0.25in]{...
user avatar
  • 123
1 vote
1 answer
52 views

Is it normal for minted to run slow?

I just install minted, but the simple command: latexmk -pdf -shell-escape main.tex with main.tex simply being: \documentclass{article} \usepackage{minted} \begin{document} \begin{minted}{r} sprem <...
user avatar
  • 11
2 votes
1 answer
71 views

Embedding code snippet in a tikzpicture

I was trying to modify a latex snippet that gave this output: so that a small C code snippet is place above the 'Code A' and 'Code B' labels as in right +--------------->--------...
user avatar
  • 189
1 vote
0 answers
49 views

Question about coloring in latex

Hello from the following code \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{float} \usepackage[a4paper,margin=1in,footskip=0.25in]{geometry} \colorlet{mygray}{black!30} ...
user avatar
  • 123
1 vote
1 answer
35 views

Latex .tex file input highlighted, listed, code

I have the latex document: \begin{document} Document introduction. \onecolumn \section*{That's how the code looks like} \begin{algorithm} \input{z.tex} \begin{algorithm} \end{document} And I ...
user avatar
0 votes
0 answers
51 views

Problem in writing Haskell Codes in Minted Package in Texstudio

I used this \documentclass[12pt]{article} \usepackage{minted} \begin{document} \begin{minted}{haskell} --type Stack a = [a] --push :: Stack a -> a -> Stack a --push xs x = x:xs --pop :: Stack ...
user avatar
1 vote
0 answers
33 views

Prevent processing of arabic text in sections

Background I am using the package arabtex to process arabic text in coding examples. However, in my main file, every time I do this the code (for example <!DOCTYPE html>) in \section{} gets ...
user avatar
  • 2,603
0 votes
1 answer
58 views

Is this symbol available in latex? [duplicate]

This G symbol is ofter used to donate a collecttion of sets or a family of intervals.
user avatar
  • 135
1 vote
1 answer
46 views

A case of code plot in C++

I am entering some C++ files inside my LateX main.tex, and it appears that LateX "writes" the space symbol when there's a space in a string inside listing. (I am using listingsutf8 package) ...
user avatar
0 votes
1 answer
41 views

Listings package in Latex with line numbers for arxiv

I'm including some code in a paper submission to arxiv (I assume to prevent galley proofs from being uploaded as discussed here: https://academia.stackexchange.com/questions/49386/why-does-arxiv-not-...
user avatar
  • 13
2 votes
1 answer
41 views

verbatim environment inside a tcolorbox results in misalignment

I'm trying to put two code examples in a tcolorbox side by side. The problem is that I am using the alltt environment a derivative of the verbatim environment. Here is my code: \begin{tcolorbox}[...
user avatar
  • 123
1 vote
1 answer
68 views

Writing `.^` in math mode (element-wise power in Julia) [duplicate]

I would like to write .^ in latex, in a math expression. I tried using \texttt{.^} but I get ^ only allowed in math mode. So I tried escaping it \texttt{.^} but this didn't work either. Essentially ...
user avatar
2 votes
1 answer
35 views

How do I set up both option frame=tb and multicols=2 in lstings environment, so that they work well at the same time

My minimal example is here: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \usepackage{multicol} \lstdefinelanguage{Cpp}{ keywords={auto, double, int, struct, break, else, long,...
user avatar
1 vote
2 answers
36 views

Tilda ups when use code cpp snippets

I use C++ code snippets with latex. I try to use verbatim, lstlisting and minted(imho which is the most beautiful). But they has one trouble. When I want to write code p->~T() I get tilda at the ...
user avatar
  • 113
1 vote
1 answer
31 views

listings package doesn't render brackets correctly

I'm trying to list some code using the listings package, however if use ttfamily font, brackets don't render correctly. This is what it looks like
user avatar
0 votes
0 answers
22 views

Highlight \lstinline, make it work with backtics

I have 2 related questions. In short, I want to make inline code snippets like in markdown: int c = 4;. The questions are: how to highlight text inside \lstinline (gray background)? is it possible to ...
user avatar
1 vote
1 answer
78 views

How can I add additional spacing between some lines in `minted`?

I would like to add a little separation between some lines of code for readibility. Consider this MWE: \documentclass{article} \usepackage{minted} \begin{document} \begin{minted}[linenos]{python} ...
user avatar
  • 585
2 votes
1 answer
51 views

tcolorbox parameter on condition

I wanted to make a tcolorbox, that centers based on the value of a variable (\standardboxwidth). I want to call the parameter center for the tcbset only if \standardboxwidth is not equal to \linewidth....
user avatar
  • 366
1 vote
1 answer
34 views

Why does the page number slightly move its position to the bottom line when a listing code is written on two pages?

I noticed that whenever I add a source code to my latex file, the numbers of the page where the code is added look displaced. I do not know if there is a reason in the listing configuration that ...
user avatar
  • 83
1 vote
1 answer
87 views

How can I make a geometric representation of an infinite sum in latex code?

I am trying to make a graphical solution for the infinite sum of 1/2^n. It is simple if we draw a 1x1 square, and start representing this sum inside the square. could someone tell me how I could draw ...
user avatar

1
2 3 4 5
14