I am trying to include python code in my lyx document by inserting a file. I began by trying to use listings but this was causing code to overflow pages.
Now I'm using pygments setting it up as described in this tutorial, http://wiki.lyx.org/Examples/IncludeExternalProgramListingUsingPygments. This appears to work fairly well but the code highlighting is off. for instance def and elif keywords are not highlighted and docstrings do not highlight if they are split over multiple lines.
I have tried changing the style to a few different built in ones but this hasn't worked.
Has anyone got a/ knows of a good way to highlight python code in the same way as idle does.
Thanks.
You should check out package called minted, although I don't know how well it works together with Lyx. But in regular latex file you can just do:
\usepackage{minted}
...
\inputminted[]{python}{python_file.py}
Related
I tried to post code examples of Python3 and it was a mess.
Here is what I get when I try using the code tags.
I found I had to go back and re-select the code after inserting it and then the CTL-k featured worked.
I had to select all but the first line (which had the proper indentation), then I used the CTL-K on the selected lines and with the indentation correct the code looked correct.
Worked way different from the wiki mark up to which I was mentally referring.
I'm using Sphinx to document a python project, and I'm trying to create a reusable tip to be used in several locations.
Typically, I'll use the following syntax in a python file:
"""
.. tip::
I want this tip to be used in several locations. Why?
- Save time
- Work less
"""
Now this works whether I put it at the beginning of the file, right under class definition or right under function definition.
I found Sphinx's manual for :ref:, which suggests to use a label:
.. _my_reusable_tip:
.. tip::
...
And then call this tip with :ref:`my_reusable_tip` anywhere I want.
The manual states that 'it works across files, when section headings are changed, and for all builders that support cross-references'
The thing is, it doesn't matter in which .py file in the project I write the label and tip definition, the :ref:`my_reusable_tip` just displays 'my_reusable_tip', and not the tip itself.
What I'm using to build the documentation is
sphinx-apidoc -f -F -o
make html
I'm pretty sure my logic is flawed in some way, but I can't figure out why.
I know that Sphinx searches the project for reStructuredText and renders it if it can, but I think I'm missing something here.
I tried to add this label in a seperate .py file enclosed in """, and in a separate .txt file without enclosed """.
I tried creating an .rst file with the label definition and rebuild the html documentation.
What am I missing here?
Python 3.4.3 BTW.
In sphinx, a :ref: is simply a more robust way of linking (or referencing) another part of the document. Thus, your use of :ref: will simply provide a hyperlink to the label.
It is not a way of substituting or expanding a block.
Inline substitutions are available using using |...|, however an inline substitution cannot be used to substitute a block as you seem to require.
RestructuredText is not a template language, and thus doesn't provide macro like facilities. In the event you need it, an alternative solution is to use a template library such as mako or jinja to deal with this kind of issue.
Just using reStructuredText directive
.. include:: ./my_reusable_tip.txt
in your rst files?
I'm documenting my Python classes using Sphinx, and sometimes I want to give my parameters quite long descriptions to explain something in details. Unfortunately, Sphinx generates ugly output for me which wastes a lot of space and breaks the whole page appearance:
It can be seen that Sphinx creates a table, then puts "Parameters" header to the left cell, and the actual list of parameters to the right cell. But there should be way to avoid creating this table completely. After playing with the page DOM tree I finally can show that I want to achieve:
Is there a built-in way to do this or I'd have to create a PR to Sphinx theme or Sphinx itself?
After posting an issue to Sphinx bug-tracker and having no response, I've decided to roll-out my own solution (better say, hack). To achieve the look I want, I have written a simple Sphinx extension which post-processes generated HTML code. It can be found on PyPI:
https://pypi.python.org/pypi/sphinxcontrib.divparams
https://pythonhosted.org/sphinxcontrib.divparams/
This doesn't seem to be the best way to solve the issue, but the behaviour I wanted to change is deeply hard-coded in docutils, not Sphinx.
I am trying to make a cookbook out of some Python snippets using Sphinx. Each snippet is a self-contained Python script and has a tutorial-type doctsring.
I want to have a source link in the generated documentation to display the script contents. But viewcode does not seem to create this link for the module, but only for a function or a class with a docstring. Is there a way to coax sphinx.ext.viewcode to display the script code without having any class/function in it?
I hope you haven't sat for two years waiting for an answer, but try using the literal include tag. You can play around with what gets displayed.
See the sphinx docs for more details.
I'm trying out PyCharm for Django development and so far am extremely happy. My team strictly follows PEP8 formatting and we use the pep8 command line program to check to make sure our code conforms.
I've configured an external tool command to run pep8 and it works good. I see the capability to create filters that will cause the output to be parsed into something PyCharm can use. I've read the docs and searched Google but can't find an example to make this work. Docs are http://www.jetbrains.com/pycharm/webhelp/add-filter-dialog.html
I'm using PyCharm 1.2 and the output filter I'm using looks like this:
$FILE_PATH$:$LINE$:$COLUMN:.*
Example output looks like this:
/home/matt/.../settings.py:13:30: E261 at least two spaces before inline comment
/home/matt/.../settings.py:20:80: E501 line too long (126 characters)
What would be even more awesome is if this could be run each time the file is saved.
You've missed a $ off the end of COLUMN. I followed your steps and I have it working perfectly. Your filter should be:
$FILE_PATH$:$LINE$:$COLUMN$:.*
Update: To have it work for PyCharm 1.5 use:
$FILE_PATH$\:$LINE$\:$COLUMN$\:.*
PyCharm expects full file path for the links to work, not just the name.