Commit 0c592f27 authored by Ingo Heimbach's avatar Ingo Heimbach

Added utilities for creating html and latex documentations from rst

files
parent 539dfc62
Copyright 2017 Forschungszentrum Jülich GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Documentation utilities
## Overview
This repository is a collection of styles and patched scripts for the Python docutils package to generate pleasant
documents from reStructuredText files.
## Files
- `rst2latex-listings.py`: Patched version of `rst2latex` using the Listings package consistently for code
highlighting
- `rst2html_githublike_fzj.css`: Stylesheet for `rst2html` fzj blue for strong emphasized text; Use the
`--syntax-highlight=short` option for `rst2html` to get proper syntax highlighting
- `rst2latex_fzj.sty`: Style with fzj colors and a custom title page
This diff is collapsed.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
"""
A customized front end to the Docutils Publisher, producing LaTeX with valid codeblocks using the listings package.
"""
try:
import locale
locale.setlocale(locale.LC_ALL, '')
except:
pass
from docutils.core import publish_cmdline
from docutils.parsers.rst import directives, Directive
from docutils import nodes
class CodeBlock(Directive):
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
has_content = True
rstlang_to_listingslang = {
'text': '{}'
}
def run(self):
language = self.rstlang_to_listingslang.get(self.arguments[0], self.arguments[0])
content = '\n'.join(self.content)
latex = '\\begin{{lstlisting}}[language={}]\n{}\n\\end{{lstlisting}}'.format(language, content)
return [nodes.raw('', latex, format='latex')]
description = ('Generates LaTeX documents from standalone reStructuredText '
'sources. '
'Reads from <source> (default is stdin) and writes to '
'<destination> (default is stdout). See '
'<http://docutils.sourceforge.net/docs/user/latex.html> for '
'the full reference.')
for directive_name in ('code', 'code-block'):
directives.register_directive(directive_name, CodeBlock)
publish_cmdline(writer_name='latex', description=description)
\ No newline at end of file
% Author: Ingo Heimbach
% Contact: i.heimbach@fz-juelich.de
%
% Style for use with Docutils/rst2latex.
\PassOptionsToPackage{warn}{textcomp}
\usepackage{lmodern}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\definecolor{fzjblue}{RGB}{0,91,130}
\renewcommand{\textbf}[1]{{\bfseries\color{fzjblue}#1}}
\lstset{
basicstyle=\ttfamily\color{black}\footnotesize,
keywordstyle=\color[RGB]{215, 58, 73},
emphstyle=\color[RGB]{0, 92, 197},
commentstyle=\color[RGB]{106, 115, 125},
stringstyle=\color[RGB]{0, 114, 0},
numbers=left,
numberstyle=\tiny\color{gray},
stepnumber=1,
tabsize=2,
breaklines,
breakatwhitespace,
showspaces=false,
showstringspaces=false,
backgroundcolor=\color[RGB]{252, 252, 255},
frame=single,
language=bash
}
\renewcommand{\maketitle}{
\begin{titlepage}
\sffamily
\makeatletter
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north] at ($(current page.center) + (0, 0.5\textheight)$) {%
\LARGE\scshape%
\parbox{\textwidth}{\centering Technische Dokumentation}%
};%
\fill[ultra thick, fill=fzjblue] ($(current page.center) + (0, 0.25\textheight) + (-0.5\paperwidth, 1.5)$) rectangle +(\paperwidth, -3);
\node at ($(current page.center) + (0, 0.25\textheight)$) {%
\LARGE\bfseries%
\parbox{\textwidth}{\centering \color{white}\@title}
};%
\node at ($(current page.center) + (0, 0.05\textheight)$) {%
\Large%
\parbox{\textwidth}{\centering \@author}
};
\node at ($(current page.center) + (0, -0.05\textheight)$) {%
\large%
\ifthenelse{\equal{\@date}{}} {
\today
}{
\@date
}
};
\node[anchor=south] at ($(current page.center) + (0, -0.5\textheight)$) {%
\parbox{\textwidth}{\centering
Forschungszentrum Jülich GmbH \\[1ex]
Peter Grünberg Institut / Jülich Centre for Neutron Science \\
Technische Administration \\
(PGI/JCNS-TA)
}%
};%
\node[anchor=south east] at (current page.south east) {
\includegraphics[scale=0.35]{logo_fzj_schutzzone}%
};%
\end{tikzpicture}
\makeatother
\end{titlepage}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment