[In] and [Out] Prompt
To change the colors of the In
and Out
prompt you can use a custom template, very similar to your attempt. Create a file (colors.tplx) with the following content:
((*- extends 'article.tplx' -*))
((* block definitions *))
((( super() )))
\definecolor{incolor}{rgb}{0.8, 0.0, 0.0}
\definecolor{outcolor}{rgb}{0.9, 0.3, 0.70}
((* endblock definitions *))
Of course, you have to adapt the colors of the prompts as you like. To use this template call ipython nbconvert --to pdf --template colors.tplx file.ipynb
.
Note, the syntax highlighting is not affected this way.
Syntax coloring
The syntax highlighting seen in the final pdf is based on pygments. The default coloring is hardcoded in the LatexPreprocessor (see here). To get a different style a custom preprocessor has to be used. A possible preprocessor is a small modification of the current LatexPreprocessor and may look like (prelatex.py)
from __future__ import print_function, absolute_import
from IPython.nbconvert.preprocessors.base import Preprocessor
class MyLatexPreprocessor(Preprocessor):
def preprocess(self, nb, resources):
# Generate Pygments definitions for Latex
from pygments.formatters import LatexFormatter
resources["latex"]["pygments_definitions"] = LatexFormatter(style='emacs').get_style_defs()
return nb, resources
Here, the emacs style is used. This works because the default LatexPreprocessor stores the pygments syntax color definitions in the resources dict, which is later pasted into the resulting .tex file. Our custom Preprocessor is executed after the default one and redefines the color definitions.
To enable this PreProcessor a custom config has to be created. This is as simple as creating a file (custom_cfg.py) like
c = get_config()
c.Exporter.preprocessors = ['prelatex.MyLatexPreprocessor']
With these both files in the working directory the nbconvert call looks like
ipython nbconvert --to latex --config custom_cfg.py file.ipynb
To get a list of the available styles the following snippet can be used.
from pygments.styles import get_all_styles
list(get_all_styles())
On my machine I get
['vs', 'pastie', 'borland', 'friendly', 'emacs', 'vim', 'native', 'perldoc', 'monokai', 'trac', 'tango', 'murphy', 'default', 'colorful', 'manni', 'bw', 'rrt', 'autumn', 'fruity']
Result
Combining both methods, ie. a custom template and a custom preprocessor the resulting pdf may look like:

You can find further information in this slightly outdated blog and this question.
Btw. I used ipython 3.0-dev (8d6041b)