{"id":1027,"date":"2016-07-07T08:35:09","date_gmt":"2016-07-07T08:35:09","guid":{"rendered":"https:\/\/block.arch.ethz.ch\/blog\/?p=1027"},"modified":"2016-07-07T08:35:09","modified_gmt":"2016-07-07T08:35:09","slug":"python-code-in-latex","status":"publish","type":"post","link":"https:\/\/block.arch.ethz.ch\/blog\/2016\/07\/python-code-in-latex\/","title":{"rendered":"Python code in LaTeX"},"content":{"rendered":"<p>Including Python code in LaTeX papers is very simple and convenient with the &#8220;listings&#8221; package. Documentation of the package is part of the (awesome) <a href=\"https:\/\/en.wikibooks.org\/wiki\/LaTeX\/Source_Code_Listings\" target=\"_blank\">LaTeX wikibook<\/a>&#8230;<\/p>\n<p><!--more--><\/p>\n<p>First, include the package in your document:<\/p>\n<pre class=\"brush:latex;toolbar:false;gutter:false\">\r\n\\documentclass{article}\r\n\r\n\\usepackage{listings}\r\n\r\n\\begin{document}\r\n\\end{document}\r\n<\/pre>\n<p>And then insert code directly in the document:<\/p>\n<pre class=\"brush:latex;toolbar:false;gutter:false\">\r\n\\lstset{language=Python}\r\n\\lstset{frame=lines}\r\n\\lstset{caption={Insert code directly in your document}}\r\n\\lstset{label={lst:code_direct}}\r\n\\lstset{basicstyle=\\footnotesize}\r\n\\begin{lstlisting}\r\nfrom brg.datastructures import Mesh\r\n\r\nmesh = Mesh.from_obj('faces.obj')\r\nmesh.draw()\r\n\\end{lstlisting}\r\n<\/pre>\n<p>Or add code from a file:<\/p>\n<pre class=\"brush:latex;toolbar:false;gutter:false\">\r\n\\lstinputlisting[language=Python]{mesh.py}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Including Python code in LaTeX papers is very simple and convenient with the &#8220;listings&#8221; package. Documentation of the package is part of the (awesome) LaTeX wikibook&#8230;<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1027","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/1027","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/comments?post=1027"}],"version-history":[{"count":5,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/1027\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/1027\/revisions\/1032"}],"wp:attachment":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/media?parent=1027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/categories?post=1027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/tags?post=1027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}