Hi,

Unfortunately, we can't use two translators at the same time. Only one
translator can be registered to the specific builder. So it would be
better to integrate these translators to a single one.

As a workaround, you can override the method of the default
LaTeXTranslator via assigning method::

    from sphinx.writers.latex import LaTeXTranslator

    original_visit_literal_block = LaTeXTranslator.visit_literal_block

    def my_visit_literal_block(self, node):
        ...

    LaTeXTranslator.visit_literal_block = my_visit_literal_block

Thanks,
Takeshi KOMIYA

2020年8月7日(金) 21:12 Yves Chevallier <canard...@gmail.com>:
>
> I am writing an extension that uses `listings` instead of `SphinxVerbatim`. 
> This extension extends the current translator:
>
> def setup(app):
>  app.set_translator('latex', MyLaTeXTranslator)
>
>  return {
>  'version': '0.1',
>  'parallel_read_safe': True,
>  'parallel_write_safe': True,
>  }
>
> Then I want to write another extension that adds a colored frame around the 
> code
>
> from sphinx.writers.latex import LaTeXTranslator
>
> class Translator(LaTeXTranslator):
>  def visit_literal_block(self, node):
>  return ''.join([
>  'foo',
>  super().visit_literal_block(node),
>  'bar'
>  ])
>
> def setup(app):
>  app.set_translator('latex', Translator)
>
>  return {
>  'version': '0.1',
>  'parallel_read_safe': True,
>  'parallel_write_safe': True,
>  }
>
> Unfortunately this lead to an error:
>
> sphinx.errors.ExtensionError: Translator for 'latex' already exists
>
>
> Extension error:
> Translator for 'latex' already exists
>
> What is the proper way to do this?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sphinx-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sphinx-users/81fb2c56-2711-4262-89a1-02a2552d1ce5o%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/CAFmkQAPotSQe1kkDr_QOmHgxAxCKLne5r1PqzckFqzAdesXaLQ%40mail.gmail.com.

Reply via email to