python - Why reflectbox doesn't work when pdflatex is called with the dvips option of graphicx package -
general overview
i want generate pdf image containing latex-style flipped character matplotlib associated package graphicx. here python code:
import matplotlib params = {'backend':'pdf', 'text.latex.preamble':['\usepackage{amsmath}', '\usepackage{graphicx}'], 'text.usetex':true} matplotlib.rcparams.update(params) import matplotlib.pyplot plt fig = plt.figure() axe = fig.add_subplot(111) axe.set_xlabel('\text{\reflectbox{$\boldsymbol{\gamma}$}}') axe.savefig('image.pdf',bbox_inches='tight')
i non-flipped character whereas same latex command compiled pdflatex works fine , gives horizontaly flipped character. apparently matplotlib generates latex-style calling dvi latex compiler force use [dvips] option graphicx package.
implementation test
i tried same syntax directly in latex , observed [dvips] option of package graphicx disable flipping behaviour of \reflectbox
command.
this code works 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 code doesn't work 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 option affecting flipping command \reflectbox
? possible generate , export character directly pdf file? know generating .dvi via latex , converting pdf possible matplotlib doesn't seem allow procedure.
remark
i found work around first objective use 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 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 solution doesn't robust one...
thanks in advance explanations!
Comments
Post a Comment