Tag Info

Hot answers tagged

24

Good approach is defining new environments for programming language. Minimal setup can be around this: \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} % Default fixed font does not support bold face \DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold \DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal % Custom colors ...


23

One option would be to use the tcolorbox package and its listings library: \documentclass{article} \usepackage{tcolorbox} \usepackage{fixltx2e} \tcbuselibrary{listings} \definecolor{color1}{RGB}{244,243,224} \definecolor{color2}{RGB}{31,174,174} \definecolor{deepblue}{rgb}{0,0,0.5} \definecolor{deepred}{rgb}{0.6,0,0} \definecolor{deepgreen}{rgb}{0,0.5,0} ...


18

PGF You might want to take a look at the mathematical capabilities of pgf. I prepared a MWE: \documentclass{standalone} \usepackage{pgf} \usepgflibrary{fpu} \pgfkeys{ /pgf/fpu = true, /pgf/number format/.cd, precision=2, fixed, fixed zerofill, use comma, 1000 sep={.} } \begin{document} \pgfmathparse{2*(1234.56+9786.45)} ...


17

The LuaTeX developers have commented on their choice of Lua over other languages, including Python, on their home page. Embedding the interpreter is one thing, and apparently no fun with Python. Another is to actually make the innards of TeX visible to the embedded interpreter. While much of the communication code could likely be adapted in some way from ...


15

Regarding flat .zip vs. .tds.zip, CTAN now rejects uploads that consist only of a TDS-structure, whether as a .zip or not. They now require creating a "browsing-friendly" relatively flat structure for the main tree. Regarding creation of .tds.zip, I would strongly discourage doing it here. And in general, unless there is a specific reason to do so. ...


15

You may be interested in my PythonTeX package. It only executes Python code when it is modified, saves all Python-generated results, and provides persistence between environments/commands. I expect that part of the problem you were running into in your example relates to the internal workings of \draw. I couldn't get an equivalent example to work with my ...


15

The code compiles fine if I remove the % characters: \documentclass{article} \usepackage{python} \begin{document} Say hello Python: \begin{python} print r"Hello \LaTeX!" \end{python} \end{document} The problem is that \begin{python} needs to see an end-of-line to start it working; and if you comment it, the next one that's seen is too late and the ...


14

I have been coding "PythonTeX" since last May, and am planning the first public release sometime between next weekend and the beginning of March. I'm actually planning to call it PythonTeX, by analogy to PerlTeX and SageTeX. I've created a LaTeX package, and accompanying Python scripts, that provide most functionality of python.sty, SageTeX, and SympyTeX, ...


11

My take is: Lua as a language was created as an embedded language and is well suited for the job. Now that with LuaTeX a scriptable TeX implementation exists, there is little principled reason to create another one. Of course, you can go ahead and create PythonTeX. But it seems that the community feels that this would not add enough value over LuaTeX to ...


11

I am also interested in generating LaTeX code with Python, so your posting gave me the hint to the framework to use. I just created a simple example: from Cheetah.Template import Template definition = """\\documentclass{article} \\title{$paper.title} \\author{$author.name} \\begin{document} \\maketitle \\end{document}""" class author: """A simple ...


11

For the problem of filling the ellipse sectors, you can draw "bigger" triangles and then clip them to the elipse shape. For this approach it is better to have the points A1, A2, B1, B7, C1 and C7 in polar coordinates. In fact, only the angle is important, since the radius will be made long enough to guarantee that the point is out of the ellipse. A radius ...


11

Henri Menke's answer is very good, but does not cover the case where you want to perform operations on large numbers before displaying them (the range of pgfmath is rather limited). Instead of pgfmath I would use l3fp, which manipulates floating point numbers with 16 significant digits, and a wide range of exponents. That should be enough for you, as long ...


10

A related problem might be separating the formatting and content of the syllabus, which could make it easier to generate as many of these syllabi as needed. It would definitely make any scripting much more robust, since you'd be generating only a simple .sty file instead of modifying a full .tex document. Sample result (close to what you had posted): ...


10

I've played around a little with the sagetex package (designing tests which can be randomized) and I think you should look into its documentation. sagetex allows you incorporate Sage into your LaTeX code. Since Sage is based Python, you can run Python using sagetex. There is a \sage command that lets you jump back in to work with variables you've defined ...


9

There is matplotlib2tikz, which creates a TikZ/pgfplots file that can be \input in your document. I don't know how well it works, having never used matplotlib, but I have used matlab2tikz from the same author, and that works well. Also, I do not know if matplotlib2tikz supports all the different kinds of plots that matplotlib can create – in the Matlab case ...


9

Not really an answer to this question as it doesn't involve Cheetah. However if anyone searches for truth table, potentially they would like a truth table macro so I'll post this for that reason. The macro \truthtable{<prims>}{<exprs>} (compile with LuaLaTeX) takes two arguments: The first argument is a comma separated list of primitives ...


8

Actually, a good way to use Python code into (plain) TeX code is: for the typesetting work (boxes, glue and penalties) use only TeX; for calculation, databases interface and so on you can build Python modules that you can call from the TeX program via \write18. The Python modules have to leave the output into files that have to be read via the usual ...


8

I would go here with an almost orthogonal answer/comment. The original TeX engine has only integer arithmetic and while TeX is Turing complete language and implementation of floating point arithmetics via integer arithmetic is certainly possible (I believe the name of the package is float-point or something like that) this is a perfect example where using ...


7

Perhaps the most robust solution for filenames is to add \usepackage{url} Then use \path{my_file_name} The url package commands take care of special symbols, and allow the line to break. You can customise the font used, see the comments in the file.


7

PythonTeX v0.12beta works with Python 2.7.3 and later, but not with Python 2.7.2 and earlier. This is due to changes introduced in 2.7.3. I will try to make the final 0.12 release work with all versions of Python 2.7. I did a little additional experimentation with Python 2.7.2, and tracked down the ultimate source of the problem. subprocess.Popen() ...


7

In your short example, you are trying to print file names. But in general, file names will not be valid LaTeX, since they may contain underscores, etc. If you do something like print('\\verb|' + name + '|\n') then the file names will be wrapped in a \verb command and thus special characters won't be an issue. Also, you don't need the % after the python ...


7

Here is a way to call into a persistent Python process from LuaTex via JSON-RPC. 1) Required setup: Download and install jsonrpclib. This provides the Python server. Download a Lua json-rpc client. I adapted some Lua modules I found on the web and zipped them up and put them on my server. Unzip into one of the directories specified in this answer: ...


7

There is also SympyTeX, a package that allows you to use the complete functionality of python and sympy within your LaTeX document. Here is an example: Using sympy within your LaTeX document is as easy as $2+2=\sympy{2+2}$. You can write a block, and then use the variables defined later in your code! \begin{sympyblock} x = sympy.Symbol('x') h ...


7

In ConTeXt, the standard way to specify such information is to use \setvariables and then access them using \getvariables. For example, for my course notes I often use \setvariables [course] [title={Name of the Course}, number={Course Number}, term={Winter 2012}, location={Room No...}, time={Tuesdays and Thursdays, ...}, ] ...


7

This is too long to be a comment, since the OP's intent is not 100% clear. There is usually very little in terms of interaction between environments used and whatever is contained within them that can be used outside of that environment. Typically, environments are used to format its contents in a general way, performing certain operations at the start of ...


7

A definitive solution could only be given by Christian Schenk, the developer of MiKTeX. I am like most others just a simple user without knowledge in reading the MiKTEX sources. But nethertheless from empiric experience I guess he removed intentionally the rudimentary Perl included in earlier versions (as already said in question: my memory can deceive me), ...


6

I think that the pdfTeX community analyzed the situation correctly when they chose Lua. Lua is intended to be embedded into other applications, and it provides a robust, easy to use C API. The Lua API is straightforward and its design eliminates the need for manual reference management in C code, unlike Python's API. Python is an opinionated language ...


6

The Keplerequation (link to German wikipedia, which is unusually more informative than the English one on this topic) has no algebraic/closed solution. There are good approximations, but if one has to be approximative from the beginning, one can also simulate the physics instead of doing the math: \documentclass{standalone} \usepackage{etoolbox} ...


6

You can use the package url as stated by David Carlisle, but if you want your filenames to be printed in italic, I suggest to define a custom command with a custom font. That is, add the following lines to your document: \usepackage{url} \def\UrlFont{\it} % italic shape for the used font \DeclareUrlCommand\itfile{\urlstyle{it}} % ...


5

I had the same problem -- working from Terminal but not in Texpad. I solved it by tweaking my Preferences for Texpad. In the typesetting pane, I enabled -shell-escape (off by default) and disabled the option to hide the intermediate files. I suspect that the error arises when pygments looks for a file but it has been named in such a way that it is not found. ...



Only top voted, non community-wiki answers of a minimum length are eligible