Python and LaTeX and pdf and png

This is a circular system of python code that documents itself in LaTeX and then converts it to pdf, then to png. There are many ways through all these connections and they can become video with voice and code. It seems to me that I could and should just generate a program that creates the content on the user's computer at their discretion, since I want no control or ownership of the source or product. In the case of a generated tutorial, it can create the slides or video and script the entire process to display and run code as well as explain what is happening. As opposed to content which is delivered in streams, the methods and materials are combined to be the product wherever it is assembled.




#!/usr/bin/env python import shlex, subprocess header='pretex.txt' middle='metex.py' tailer='posttex.txt' product='product.tex' h=open(header,'r') t=open(tailer,'r') m=open(middle,'r') p=open(product,'w') p.write(h.read()) p.write(m.read()) p.write(t.read()) h.close() t.close() p.close() m.close() shell_cmd='pdflatex product.tex' args=shlex.split(shell_cmd) retcode = subprocess.call(args,stdout=None) shell_cmd='convert product.pdf product.png' args=shlex.split(shell_cmd) retcode = subprocess.call(args)

This is the file "pretext.txt"


\documentclass{article} \usepackage{color} \usepackage{listings} \usepackage{textcomp} \usepackage{setspace} \usepackage{palatino} \renewcommand{\lstlistlistingname}{Code Listings} \renewcommand{\lstlistingname}{Code Listing} \definecolor{gray}{gray}{0.5} \definecolor{green}{rgb}{0,0.5,0} \lstnewenvironment{python}[1][]{ \lstset{ language=python, basicstyle=\ttfamily\small\setstretch{1}, stringstyle=\color{red}, showstringspaces=false, alsoletter={1234567890}, otherkeywords={\ , \}, \{}, keywordstyle=\color{blue}, emph={access,and,break,class,continue,def,del,elif,else,% except,exec,finally,for,from,global,if,import,in,is,% lambda,not,or,pass,print,raise,return,try,while}, emphstyle=\color{black}\bfseries, emph={[2]True, False, None, self}, emphstyle=[2]\color{green}, emph={[3]from, import, as}, emphstyle=[3]\color{blue}, upquote=true, morecomment=[s]{"""}{"""}, commentstyle=\color{gray}\slshape, emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, emphstyle=[4]\color{blue}, literate=*{:}{{\textcolor{blue}:}}{1}% {=}{{\textcolor{blue}=}}{1}% {-}{{\textcolor{blue}-}}{1}% {+}{{\textcolor{blue}+}}{1}% {*}{{\textcolor{blue}*}}{1}% {!}{{\textcolor{blue}!}}{1}% {(}{{\textcolor{blue}(}}{1}% {)}{{\textcolor{blue})}}{1}% {[}{{\textcolor{blue}[}}{1}% {]}{{\textcolor{blue}]}}{1}% {<}{{\textcolor{blue}<}}{1}% {>}{{\textcolor{blue}>}}{1},% framexleftmargin=1mm, framextopmargin=1mm, frame=shadowbox, rulesepcolor=\color{blue},#1 }}{} \lstnewenvironment{latex}[1][]{ \lstset{ language=latex, basicstyle=\ttfamily\small\setstretch{1}, stringstyle=\color{red}, showstringspaces=false, alsoletter={1234567890}, otherkeywords={\ , \}, \{}, keywordstyle=\color{blue}, emph={access,and,break,class,continue,def,del,elif,else,% except,exec,finally,for,from,global,if,import,in,is,% lambda,not,or,pass,print,raise,return,try,while}, emphstyle=\color{black}\bfseries, emph={[2]True, False, None, self}, emphstyle=[2]\color{green}, emph={[3]from, import, as}, emphstyle=[3]\color{blue}, upquote=true, morecomment=[s]{"""}{"""}, commentstyle=\color{gray}\slshape, emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, emphstyle=[4]\color{blue}, literate=*{:}{{\textcolor{blue}:}}{1}% {=}{{\textcolor{blue}=}}{1}% {-}{{\textcolor{blue}-}}{1}% {+}{{\textcolor{blue}+}}{1}% {*}{{\textcolor{blue}*}}{1}% {!}{{\textcolor{blue}!}}{1}% {(}{{\textcolor{blue}(}}{1}% {)}{{\textcolor{blue})}}{1}% {[}{{\textcolor{blue}[}}{1}% {]}{{\textcolor{blue}]}}{1}% {<}{{\textcolor{blue}<}}{1}% {>}{{\textcolor{blue}>}}{1},% framexleftmargin=1mm, framextopmargin=1mm, frame=shadowbox, rulesepcolor=\color{blue},#1 }}{} \begin{document} We can see in Code Listing~\ref{ex1} that it is creating itself using this as a template, compared to Code Listing~\ref{ex2} which is something else. \begin{python}[caption={Self reference python example},label=ex1]

This is the file "posttext.txt"


\end{python} \begin{python}[caption={stupid python example},label=ex2] if this_is python3: print( ``this``) \end{python} \lstlistoflistings \end{document}

The automation of content production extends to the level of the blender animation and video product. It is easy enough to create audio visual content with voice, mood and background music, as well as animations of process to demonstrate relationships. The idea of content solely for entertainment would not interest me, but the instructions on how to assemble, program and maintain systems is a worthwhile endeavor. Partly because I forget how to do some complex things and need to refresh my memory occasionally.

0 comments:

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen