Questions tagged [python]
Python is a general-purpose, interpreted high-level programming language.
460 questions
7
votes
1
answer
169
views
LaTeX environment to write verbatim Python code to an external file
I’d like to have a solution environment that does the following:
It writes the contents of the environment to an external file \jobname.py. All the solutions should be in the same file \jobname.py.
...
0
votes
0
answers
86
views
Pygments: Python keywords
I am starting to use Pygments, via the LaTeX minted package. My goal is to typeset Python code using the highlighting scheme used in JupyterLab, or something close to that. Starting with the default ...
3
votes
1
answer
180
views
minted pygments dark style do not have optimization for LaTeX syntax
I have a question .
When I use pygments dark style material , I notice that many words are invisible when displaying LaTeX/text source code , since the key/value pairs are all black . These dark ...
1
vote
2
answers
133
views
how to make an environment to write python in lyx?
I'm looking to write some Python code (just for the look, no need to run it), I want it to have the distinct color palette that most Python 3 IDEs use. (in dark mode specifically)
I understand it's ...
0
votes
1
answer
80
views
LaTeX is trying to write to python file although just call file to be read
For some reason, in the code below, LaTeX is overwriting my .py file although I am just trying to call the .py file. Here is the contents of the pycode_batch_noreg.py file:
import network3
from ...
2
votes
0
answers
69
views
Strange behavior while using Matplotlib + Times generated image in LaTeX + TikZ
Short version: Some characters in images generated using Matplotlib in Python with Times fonts do not appear in LaTeX file under some conditions.
With details:
I observed this behavior by chance. I ...
0
votes
0
answers
54
views
Indentation in python codes get lost when using package pythonhighlight
I wrote an introduction note about python, which included something like the following
...
\usepackage{pythonhighlight}
...
the following indentation works in python
\begin{python}
a=5
if a==4:
...
0
votes
0
answers
185
views
How can I create and use a custom syntax highlight style for minted?
As far as I know, the information is scattered, and there isn't a straightforward tutorial that makes this easy to accomplish. The only question that specifically addressed this has been closed and ...
3
votes
4
answers
245
views
Package memoize (python-based extraction) Error: Python module 'pdfrw' was not found
I’m looking forward to running the memoize package to reduce my compile time, but after several days of research, I’m clueless. This is my first Python rodeo, so I may be missing something that to ...
1
vote
0
answers
130
views
How to Sanitize Strings in Python for Safe LaTeX Compilation with pdflatex? [closed]
I'm using Python scripts to dynamically generate LaTeX PDFs based on a template that includes several user-provided fields such as:
username
error type
input description
error message
The content ...
2
votes
1
answer
234
views
You can't use `macro parameter character #' in horizontal mode. I can't print a code .py with special characters
I have this two simple lines of python code (test.py):
#################################################
# col.set_
and this is my latex code:
\documentclass[letterpaper,12pt]{report}
\usepackage[...
1
vote
1
answer
88
views
How Can I change the colors of variables in lstlistings?
So I have some code blocks like the followings
\begin{lstlisting}[language=Python, caption={Ejecución de prueba}]
altura_lista = altura.tolist()
peso_lista = peso.tolist()
w, b = train(altura_lista, ...
0
votes
1
answer
99
views
Package pgf Error: No shape named * is known in LaTeX with TikZ for Neural Network Plot
I'm working on visualizing a neural network architecture using LaTeX with TikZ, specifically using the PlotNeuralNet library. I am encountering an error related to node referencing.
The latex code is ...
0
votes
0
answers
382
views
"An associated PostScript font (required by Matplotlib) could not be found for TeX font 'zptmcm7y' in
An associated PostScript font (required by Matplotlib) could not
be found for TeX font 'zptmcm7y' in
'C:/Users/Admin/AppData/Local/MiKTeX/fonts/map/pdftex/pdftex.map';
this problem can often be ...
1
vote
0
answers
1k
views
using pylatex but it says no compiler found
So, I'm trying to use python to compile some latex. For this very basic pylatex code:
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import NoEscape
# Create a new ...
0
votes
0
answers
124
views
PDF file generated by Latex, how to extract (matlab/python) source code (verbatim/listings)
This is a bit bizarre. I have to review a bunch of PDF files, generated by Latex (but I don't have access to the source files) and that includes
matlab or python code, that was included with listings ...
1
vote
0
answers
149
views
Can you use latexmk on Overleaf to generate multiple latex files?
I'm trying to shuffle multiple choice exams and choices. I've got python code but want to be able to run it on Overleaf.com. Tried with latexmkrc file below but couldn't generate multiple outputs. You ...
0
votes
0
answers
48
views
package pythonhighlight isnt rendering in LyX 2.3.7
when I use this package in LyX it doesn't render at all without raising any errors.
the same code on overleaf works completely fine and as intended.
here's a picture from lyx of the code itself and ...
1
vote
1
answer
491
views
pgf import in LaTeX not working due to matplotlib axes font
I was plotting as usual and then after saving one of my plots as a pgf and then compiling LaTeX it didn't work anymore. As far as I'm aware of, I didn't change anything it just so happen to top ...
0
votes
2
answers
86
views
Multi-colored and multi-bar grouped charts [duplicate]
I have a Python script that automatically generates LaTeX codes that plot bar charts. An example of the generated code looks like:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\...
0
votes
1
answer
178
views
Reproducing Python/Programming Code Blocks with modification
I want to be able to reproduce this environment within the context of exam correction.
One clue I found is the usage of the bclogo package.
https://ctan.org/pkg/bclogo
Howerver, I would like to ...
0
votes
0
answers
823
views
Manim Latex error converting to dvi
I'm not able to use Latex on Manim due to an error converting dvi. I saw other post about this and I change my code but it still does not work. Here is my code :
from manim import *
class dvi_error(...
1
vote
2
answers
325
views
How to avoid code block splitting over 2 pages with Minted
I was wondering if there is a simple way to insert a page break when a too long Python code has a function splited over 2 pages and won't fit inside current page?
The page break should be placed just ...
0
votes
0
answers
71
views
Link on pdf triggers .sh/.py/.bat
I have been looking for a while for a solution in LaTex. My intention is to create a link inside a PDF generated with LaTex that triggers a .sh/.py/.bat by clicking in the link. Not like \write18, ...
2
votes
1
answer
218
views
Hiding python comments with Listings
I want to include Python code to be formatted with listings but I just want the code neat and compact. No comments shall be printed at all, as well as no empty lines.
The easy way would be to strip ...
0
votes
1
answer
139
views
Unable to write a fraction in JupyterLab
I am trying to write a fraction inside the superscript of a variable (in my case $frac{1}{3}$.
I get a long error:
plt.ylabel('$\\frac{\delta T}{\delta t}$ $[^oR/min]$')
0
votes
5
answers
884
views
How to include result values in a LaTeX document?
We are often in the following situation: a lengthy (data analysis) computation spits out a bunch of result values. Imagine a Python or script or an R script doing some resource intensive calculations.
...
0
votes
1
answer
129
views
Automatically creating a grid of images
I have several pdf images that I have generated with matplotlib. I want to be able to arrange them in an arbitrary grid. For this purpose I have written a python script that in turn writes and runs ...
2
votes
1
answer
184
views
Piton and Pyluatex environments : write the content to an external file
I have a few environments for Python created from piton package on the one hand, and Pyluatex on the other.
Sometimes I'd like to copy their contents into an external python file (which is then ...
0
votes
0
answers
85
views
Customize minted environment w.r.t IDLE
I'm writing a document using Python code and I want to make it like IDLE style. With minted, we can custom the environment so that each line of code starts with >>>, however, I want >>&...
0
votes
1
answer
127
views
Customizations of minted environment in LaTeX [closed]
I'm using minted to write Python code in my document. I have two question as follows:
Can we reduce \begin{minted}{python} \end{minted} into simpler command like \begin{mtpt} \end{mtpt}? In fact I ...
2
votes
1
answer
877
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 --...
0
votes
2
answers
560
views
Executing python script or code using \input not working
Im trying to execute a python script from within LaTeX by means of using the \input command, however I get a strange error that I can't really understand. Im following the working example taken from ...
1
vote
0
answers
163
views
Packages ucs and hyperref don't get along under xelatex
I'm getting an "undefined control sequence" error for \UTFviii@loop whenever I use both the ucs package and the hyperref package under XeLaTeX (and LuaLaTeX). (I understand \UTFviii@loop has ...
0
votes
0
answers
176
views
Python from LaTeX: Strange Networkx/Graphviz error
It is hard to give a minimal example, because Python3 with some packages is needed. I want to call Python from LaTeX, here is an example how I want to do it (--shell-escape is needed):
\documentclass[]...
0
votes
1
answer
363
views
How to configure the Python library latexmake to run with luaLaTeX?
I am working on automated templates, and I want to use latexmake with luaLaTeX, as suggested in a comment on this question, where I attempted a similar setup with XeLaTeX. However, I am facing ...
0
votes
0
answers
50
views
SageTeX does not work when TABs are used as indents
I wrote two practically identical files that use SageTeX to determine whether a positive integer is odd or even. The first example uses tabs for indentation.
\documentclass{article}
\usepackage{...
1
vote
1
answer
452
views
Error With LaTeX (TeXStudio) Package "Pygmentize"
After downloading the Minted and Pygmentize packages for TeXstudio, I am experiencing an error:
File 'pygmentize.sty' not found. \begin.
Here is the code for my document so far:
\documentclass{...
0
votes
1
answer
182
views
Remove extra spaces and curly braces latex code in string Python (normalize string in python)
I want to normalize string in python. For example, I have a LaTeX code
str='{{{ \\dfrac{{3}}{{4}} + \\sqrt{3} }}}'
I want to get the string
str='{\\dfrac{3}{4}+\\sqrt{3}}'
Remove extra ...
0
votes
1
answer
781
views
Markdown using LaTeX: Quotation marks in PyCharm vs. Github
I'm used to typing typographically correct English quotation marks as follows:
``text goes here"
In usual LaTeX documents this will work, no questions asked. When I use Markdown in Jupyter ...
2
votes
1
answer
115
views
Minted inside xsim environment
It is needed to insert a Minted inside xsim environment. The basic code is as follow:
\documentclass{book}
\usepackage{xcolor}
\usepackage{minted}
\usepackage[verbose]{xsim}%paquete de ejercicios ...
2
votes
0
answers
101
views
Set Python's decorators in some colour but keep @ as an operator unchanged
I am using listings for code formatting and colouring in a document I'm working on, including a lot of Python code. I would like for decorators to be displayed in a specific colour but for the @ ...
1
vote
0
answers
107
views
tcolorbox minted doesnot break python docstring
I try to produce boxed minted code in Python, and it does not break Python docstring. I have tried different break... options, unsuccessfully.
MVE as follows:
\documentclass{article}
\usepackage{...
2
votes
1
answer
312
views
Ticks scaling - How to change the common factor multiplier to an offset value?
I am plotting the following figure using Python and I obtain this render:
Here, Python is automatically adding an constant value offset (+9.192682e9) on the y axis to read more easily the data.
Now, ...
1
vote
0
answers
415
views
LaTex Jupyter Notebook "Undefined Control Sequence"
I am attempting to save down a Jupyter notebook to a PDF using LaTex. I just installed the latest version of LaTex through Jupyter terminal but when I run
jupyter nbconvert --to pdf mynotebook.ipynb
...
0
votes
1
answer
537
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!
0
votes
0
answers
370
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 ...
2
votes
1
answer
134
views
`pythontex` and `\subfigure`
pythontex causing error with \subfigure environment.
I have to rewrite my dissertation with many figures and subfigures, of which some are plotted with python inside LaTeX (I had to give up the python ...
2
votes
2
answers
275
views
mwrep and pythontex -- is it possible to use
The question: possibility of using of working python scripts embedded in LaTeX.
When I was using \usepackage{python}, it did wonders to my dissertation (although I am very new to LaTeX, but some ...
7
votes
4
answers
20k
views
Package minted Error: You must have `pygmentize' installed to use this package, while Pygments is already installed?
Installed MacTex2023 on a new Mac and all is well except for a nagging issue with "pygmentize" that I've already installed. I cannot find how to adjust system to recognise the installed &...