Questions tagged [python]

Python is a general-purpose, interpreted high-level programming language.

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, http://www.python.org/, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python Tutorial

Syntax Highlighting

If your question or answer includes Python code, you can enable Python syntax highlighting by doing the following:

<!-- language: lang-py -->

    code goes here

Here's what it looks like on a “Hello, world!” program:

#!/usr/bin/env python3

def main():
    print('Hello, world!')

if __name__ == '__main__':
    main()

Frequently Asked Questions

  1. How can I get Python syntax highlighting for the listings package?
  2. Issues with Perl or Python scripts when installing
  3. Using Python within LaTeX
  4. Generating a truth table in LaTeX using the Cheetah framework
446 questions
13
votes
0 answers

Matplotlib and Python as the main TeX graphics engine

As many people here who do some scientific computing, I'm increasingly using Python as my main prototyping language in favor of MATLAB. A colleague of mine whose husband got me into Python approached me recently soliciting advice about graphics…
9
votes
3 answers

pythontex - How to choose the version of Python used?

I have two versions. How can I tell to pythontex the path to the Python3 to be used if it is possible ?
projetmbc
  • 13,315
8
votes
2 answers

Underscore in filenames in \textit{} imported from a python script

I'm trying to import the name of a result file from a python script and displaying it in the report. In the LaTeX template I have a bunch of variables defined as ${variablename}. The python script changes this into the actual variable values. I only…
huyx
  • 83
7
votes
1 answer

Can I execute python code inside LaTeX

I come to you this time not with a bit of code but with a large question: Is there a simple way to run some python code inside my document ? I came across some options : Sage : Quite a heavy installation... and in the end couldn't make it work. An…
LMT-PhD
  • 1,244
7
votes
1 answer

Pass (La)TeX-Length as function argument using pythontex

I'm trying to pass a LaTeX-Length (\textwidth) to a python function specified in an pyblock-environment provided by the pythontex-package. Running pythontex gives me an error message, that does not provide any help to me: This is PythonTeX…
7
votes
1 answer

String Formatting when using PythonTex

First of all, many thanks to Geoffrey Poore, the creator of PythonTex. PythonTeX is awesome. I am trying to use it for the first time and really like what it can do. I am having some trouble with using string formatting when using PythonTeX to…
6
votes
2 answers

Python and TeX, pythontex or hybrid-latex recommended?

I am looking into starting to use Python and (La)TeX together. Now I see two packages on ctan, pythontex and hybrid-latex. What are the pros and cons? What is the better-developed solution (with reasoning)? Is there an expectation of what the future…
Matthias Arras
  • 966
  • 6
  • 19
6
votes
1 answer

pythontex - reading data from a file

This is about a file location problem while using pythontex (which works great!) I have some python code within \begin{pylabblock} \end{pylabblock} where I am reading in data from a file in the current directory code fragment filename =…
5
votes
1 answer

Python code in LaTeX not running

The Latex/Python Project: Create in Latex a songbook from pdf files in a folder and make a toc. Problem: The code below is not running in Latex. Thanks to G.Poore I added the \verb command to overcome problems with underscores etc. Still, it doesnt…
Andreas
  • 111
3
votes
2 answers

Can we import Python file in latex?

eg. Let say we have a python file songbook-makeindex.py which required input as .xsd file extension and give output as .sbx file extension, which needs to be run inside the latex file. \documentclass{article} {here some required…
Biki Teron
  • 3,275
3
votes
2 answers

Embedding Python in LaTeX

As of today, what is the best package for embedding functional Python code in LaTeX? I've searched this site and others, which recommend the python, pythontex, and sympy packages, amongst others, but the information is somewhat dated. I want to know…
NVaughan
  • 8,175
3
votes
1 answer

pythontex + sage preparsing

I am trying to use pythontex for SAGE computations inside a .tex document. I am aware that there exists a sagetex engine which allows for exactly my use case, but pythontex's concept of sessions is specially useful for me (some computations are very…
Koji
  • 1,476
3
votes
1 answer

pythontex custom commands for pyconsole

I'm trying to use PythonTex (v 0.14), its pyconsole environment, and custom commands, and having some trouble. Here is an MWE: \documentclass[article,letterpaper,times,11pt]{article} \usepackage[gobble=auto]{pythontex} \pythontexcustomc{py}{a=1;…
mankoff
  • 2,756
3
votes
1 answer

PythonTeX rendering problem

I tried the PythonTeX package, and the output it produced contained question marks instead of running python code, what should i do ??
2
votes
0 answers

Showing jupyter notebook files in latex

I'm currently working on my thesis. And I've written some python code in Jupyter notebook files and I would like to show these files in latex. How can I do this best? Regards
1
2 3