Why reflectbox doesn't work when pdflatex is called with the dvips option of graphicx package

260 views Asked by At

General overview

I want to generate a pdf image containing latex-style flipped character with matplotlib associated to the package graphicx. Here is my python code:

import matplotlib
params = {'backend':'pdf',
          'text.latex.preamble':['\usepackage{amsmath}',
                                 '\usepackage{graphicx}'],
          'text.usetex':True}
matplotlib.rcParams.update(params)
import matplotlib.pyplot as plt
fig = plt.figure()
axe = fig.add_subplot(111)
axe.set_xlabel('\text{\reflectbox{$\boldsymbol{\Gamma}$}}')
axe.savefig('image.pdf',bbox_inches='tight')

I get a non-flipped character whereas the same latex command compiled with pdflatex works fine and gives a horizontaly flipped character. Apparently matplotlib generates the latex-style by calling dvi latex compiler which force to use the [dvips] option for the graphicx package.

Implementation test

I tried the same syntax directly in latex and observed that the [dvips] option of the package graphicx disable the flipping behaviour of the \reflectbox command.

This code works with pdflatex compiler:

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\newcommand\rvrs[1]{\text{\reflectbox{$#1$}}}
\def\myusersymb{\boldsymbol{\Gamma}}
\DeclareRobustCommand{\myrvrssymb}{\rvrs{\myusersymb}}

\begin{document}
\section{symbol in text}
symbol : $\myusersymb$\\
reversed symbol : $\myrvrssymb$
\section{symbol in caption}
\begin{figure}[!h]
   \caption{symbol : $\myusersymb$}
\end{figure}
\begin{figure}[!h]
   \caption{reversed symbol : $\myrvrssymb$}
\end{figure}
\end{document}

whereas this code doesn't work with the same compiler:

\documentclass{article}
\usepackage{amsmath}
\usepackage[dvips]{graphicx}

\newcommand\rvrs[1]{\text{\reflectbox{$#1$}}}
\def\myusersymb{\boldsymbol{\Gamma}}
\DeclareRobustCommand{\myrvrssymb}{\rvrs{\myusersymb}}

\begin{document}
\section{symbol in text}
symbol : $\myusersymb$\\
reversed symbol : $\myrvrssymb$
\section{symbol in caption}
\begin{figure}[!h]
   \caption{symbol : $\myusersymb$}
\end{figure}
\begin{figure}[!h]
   \caption{reversed symbol : $\myrvrssymb$}
\end{figure}
\end{document}

Question

Why this option is affecting the flipping command \reflectbox? Is it possible to generate and export this character directly to a pdf file? I know that generating a .dvi via latex and converting it to a pdf is possible but matplotlib doesn't seem to allow this procedure.

Remark

I found a work around for the first objective which is to use to following code:

import os
import matplotlib
params = {'backend':'ps',
          'text.latex.preamble':['\usepackage{amsmath}',
                                 '\usepackage[dvips]{graphicx}'],
          'text.usetex':True}
matplotlib.rcParams.update(params)
import matplotlib.pyplot as plt
fig = plt.figure()
axe = fig.add_subplot(111)
axe.set_xlabel('\text{\reflectbox{$\boldsymbol{\Gamma}$}}')
axe.savefig('image.eps',bbox_inches='tight')
os.system('epstopdf image.eps')

But this solution doesn't look like a robust one...

Thanks in advance for your explanations!

0

There are 0 answers