mirror of
https://github.com/mghansen256/pythontex-wrapper.git
synced 2024-10-27 20:34:03 +00:00
Initial import.
This commit is contained in:
commit
28f7d57840
214
demo-document.lyx
Normal file
214
demo-document.lyx
Normal file
@ -0,0 +1,214 @@
|
||||
#LyX 2.3 created this file. For more info see http://www.lyx.org/
|
||||
\lyxformat 544
|
||||
\begin_document
|
||||
\begin_header
|
||||
\save_transient_properties true
|
||||
\origin unavailable
|
||||
\textclass article
|
||||
\begin_preamble
|
||||
\usepackage[gobble=auto]{pythontex}
|
||||
\end_preamble
|
||||
\use_default_options true
|
||||
\maintain_unincluded_children false
|
||||
\language english
|
||||
\language_package default
|
||||
\inputencoding auto
|
||||
\fontencoding global
|
||||
\font_roman "default" "default"
|
||||
\font_sans "default" "default"
|
||||
\font_typewriter "default" "default"
|
||||
\font_math "auto" "auto"
|
||||
\font_default_family default
|
||||
\use_non_tex_fonts false
|
||||
\font_sc false
|
||||
\font_osf false
|
||||
\font_sf_scale 100 100
|
||||
\font_tt_scale 100 100
|
||||
\use_microtype false
|
||||
\use_dash_ligatures true
|
||||
\graphics default
|
||||
\default_output_format pdf2
|
||||
\output_sync 0
|
||||
\bibtex_command default
|
||||
\index_command default
|
||||
\paperfontsize default
|
||||
\spacing single
|
||||
\use_hyperref true
|
||||
\pdf_title "pythontex-wrapper for lyx demo document"
|
||||
\pdf_author "Michael G. Hansen"
|
||||
\pdf_bookmarks true
|
||||
\pdf_bookmarksnumbered false
|
||||
\pdf_bookmarksopen false
|
||||
\pdf_bookmarksopenlevel 1
|
||||
\pdf_breaklinks false
|
||||
\pdf_pdfborder false
|
||||
\pdf_colorlinks false
|
||||
\pdf_backref false
|
||||
\pdf_pdfusetitle true
|
||||
\papersize default
|
||||
\use_geometry false
|
||||
\use_package amsmath 1
|
||||
\use_package amssymb 1
|
||||
\use_package cancel 1
|
||||
\use_package esint 1
|
||||
\use_package mathdots 1
|
||||
\use_package mathtools 1
|
||||
\use_package mhchem 1
|
||||
\use_package stackrel 1
|
||||
\use_package stmaryrd 1
|
||||
\use_package undertilde 1
|
||||
\cite_engine basic
|
||||
\cite_engine_type default
|
||||
\biblio_style plain
|
||||
\use_bibtopic false
|
||||
\use_indices false
|
||||
\paperorientation portrait
|
||||
\suppress_date false
|
||||
\justification true
|
||||
\use_refstyle 1
|
||||
\use_minted 0
|
||||
\index Index
|
||||
\shortcut idx
|
||||
\color #008000
|
||||
\end_index
|
||||
\secnumdepth 3
|
||||
\tocdepth 3
|
||||
\paragraph_separation indent
|
||||
\paragraph_indentation default
|
||||
\is_math_indent 0
|
||||
\math_numbering_side default
|
||||
\quotes_style english
|
||||
\dynamic_quotes 0
|
||||
\papercolumns 1
|
||||
\papersides 1
|
||||
\paperpagestyle default
|
||||
\tracking_changes false
|
||||
\output_changes false
|
||||
\html_math_output 0
|
||||
\html_css_as_file 0
|
||||
\html_be_strict false
|
||||
\end_header
|
||||
|
||||
\begin_body
|
||||
|
||||
\begin_layout Title
|
||||
pythontex-wrapper for lyx demo document
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Now let's call some Python code:
|
||||
\begin_inset ERT
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
|
||||
\backslash
|
||||
begin{pycode}[sessionA]
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
import sys
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
print(
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
|
||||
\backslash
|
||||
|
||||
\backslash
|
||||
begin{itemize}
|
||||
\begin_inset Quotes erd
|
||||
\end_inset
|
||||
|
||||
)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
print("
|
||||
\backslash
|
||||
|
||||
\backslash
|
||||
item Running Python works.
|
||||
\backslash
|
||||
n")
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
print(
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
|
||||
\backslash
|
||||
|
||||
\backslash
|
||||
item Python version:
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
+sys.version)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
print(
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
|
||||
\backslash
|
||||
|
||||
\backslash
|
||||
end{itemize}
|
||||
\begin_inset Quotes erd
|
||||
\end_inset
|
||||
|
||||
)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
|
||||
\backslash
|
||||
end{pycode}
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
We can also use bibtex to cite something, for example IPython
|
||||
\begin_inset CommandInset citation
|
||||
LatexCommand cite
|
||||
key "Perez2007IPython"
|
||||
literal "false"
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset CommandInset bibtex
|
||||
LatexCommand bibtex
|
||||
btprint "btPrintCited"
|
||||
bibfiles "references"
|
||||
options "plain"
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_body
|
||||
\end_document
|
54
pythontexwrapper.sh
Executable file
54
pythontexwrapper.sh
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
# Wrapper around pdflatex to use pythontex in lyx
|
||||
# Author: Michael G. Hansen
|
||||
|
||||
# @TODO Make these configurable either via command-line or
|
||||
# by changing the executable name
|
||||
latexcommand="pdflatex"
|
||||
pythontexcommand="pythontex3"
|
||||
|
||||
if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
|
||||
echo "pythontex-wrapper V0.1, licensed CC0-1.0"
|
||||
echo "Wrapper around ${latexcommand} for to use ${pythontexcommand} in lyx."
|
||||
echo "See source code for details."
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# print some debug information
|
||||
echo "pythontex-wrapper.sh"
|
||||
echo "arguments:" $@
|
||||
logfilename=`basename $1 .tex`.log
|
||||
echo "Log file: " ${logfilename}
|
||||
echo "Working directory: " `pwd`
|
||||
echo "Using latex command: " ${latexcommand}
|
||||
echo "Using pythontex command: " ${pythontexcommand}
|
||||
|
||||
# compile using latex
|
||||
if ${latexcommand} $@ ; then
|
||||
# compilation in latex worked, run pythontex3
|
||||
if ${pythontexcommand} $1 ; then
|
||||
# pythontex worked, run latex again
|
||||
if ${latexcommand} $@ ; then
|
||||
# compilation in latex worked
|
||||
exit 0
|
||||
else
|
||||
# compilation using latex failed
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# running pythontex failed
|
||||
# lyx expects LaTeX error messages in the log file
|
||||
# Add a fake latex error message which lyx understands
|
||||
echo "! Undefined control sequence." >>${logfilename}
|
||||
echo "l.17 \\pythontexError" >>${logfilename}
|
||||
echo "\\Actually there is a pythontex error, see complete log for details." >>${logfilename}
|
||||
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# compilation using latex failed
|
||||
exit 1
|
||||
fi
|
15
references.bib
Normal file
15
references.bib
Normal file
@ -0,0 +1,15 @@
|
||||
@ARTICLE{Perez2007IPython,
|
||||
author = {P\'erez, Fernando and Granger, Brian E.},
|
||||
title = {{IP}ython: a System for Interactive Scientific Computing},
|
||||
journal = {Computing in Science and Engineering},
|
||||
volume = {9},
|
||||
number = {3},
|
||||
pages = {21--29},
|
||||
month = may,
|
||||
year = 2007,
|
||||
url = "https://ipython.org",
|
||||
ISSN = "1521-9615",
|
||||
doi = {10.1109/MCSE.2007.53},
|
||||
publisher = {IEEE Computer Society}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user