Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

latex - create a role (font color) in sphinx that works with `make latexpdf`

I'm used to write Rest documents while I never used LaTex.

What I would like to do is create some font color roles that I can add inline the text (e.g. :red:this text is red) that work both in html and in latexpdf compilation.

I've found a similar question here, but I cannot reproduce it.

I think that the magic will be done changing the conf.py file, but I didn't find out how.

Moreover, during the latexpdf compilation, in the _build/latex directory, there is a sphinx.sty file that contains a lot of things for the customization of the final pdf file.

If I want to change some parameter of the final pdf file, have I to edit this file, put it somewhere and tell sphinx to take this style file?

Sorry for all these stuff, but I'm a little bit confused..

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just add:

  1. a 'source/_templates/layout.html' file with

    {% extends "!layout.html" %}
    
    {% block extrahead %}
    <link rel="stylesheet" type="text/css" 
         href="{{ pathto('_static/custom.css', 1) }}" /> 
    
    {% endblock %}
    
  2. a 'source/_static/custom.css' file with

    @import url("default.css");
    
    .red {
      color: red;
    }
    

You can now use a :red: role in your rst files. Don't forget the back tick and the clean target after html or css editions:

A :red:`red`text

$> make clean html

The global tree:

test-sphinx
├── Makefile
├── build
└── source
    ├── _static
    │?? └── custom.css
    ├── _templates
    │?? └── layout.html
    ├── conf.py
    └── index.rst

An index.rst example:

TS test!
========

.. role:: red

This is :red:`just` a test …

Hope this help,

Antoine


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...