#StackBounty: #latex #python-sphinx #tikz hf-tikz and sphinx are not playing well together

Bounty: 50

I am trying to add some color to my matrices in sphinx. I was using hf-tikz for it before. However, when I add it to Sphinx, it renders it incorrectly.

The result that I am trying to get is

enter image description here

The result I am getting is

enter image description here

Here is the code that I have.

main.rst:

.. math::

    left(begin{array}{cc}
        tikzmarkin[style red]{a}atikzmarkend{a}
      & tikzmarkin[style green]{b}btikzmarkend{b} \
        tikzmarkin[style blue]{c}ctikzmarkend{c}
      & tikzmarkin[style orange]{d}dtikzmarkend{d} \
    end{array}right)
    star
    left(begin{array}{cc}
        tikzmarkin[style red]{w}wtikzmarkend{w}
      & tikzmarkin[style green]{x}xtikzmarkend{x} \
        tikzmarkin[style blue]{y}ytikzmarkend{y}
      & tikzmarkin[style orange]{z}ztikzmarkend{z} \
    end{array}right)
    =
    left(begin{array}{cc}
        tikzmarkin[hor=style red]{aw}{astar w}tikzmarkend{aw}
      & tikzmarkin[hor=style green]{bx}bstar xtikzmarkend{bx} \
        tikzmarkin[hor=style blue]{cy}cstar ytikzmarkend{cy}
      & tikzmarkin[hor=style orange]{dz}dstar ztikzmarkend{dz} \
    end{array}right)

conf.py

extensions = [
  'sphinx.ext.imgmath',
]

# Math configurations (https://tex.stackexchange.com/a/69770/51173)
imgmath_image_format = 'svg'
imgmath_use_preview = True
imgmath_latex_preamble = r'''
  usepackage{xcolor}
  usepackage[customcolors]{hf-tikz}
  colorlet{myred}{red!50!purple!30}
  colorlet{mygreen}{green!50!lime!60}
  colorlet{myblue}{blue!50!white!50}
  colorlet{myorange}{orange!80!red!60}
  colorlet{mycyan}{cyan!90!blue!60}
  colorlet{mymagenta}{magenta!90!red!60}
  tikzset{
    style red/.style={
      set fill color=myred,
      set border color=white,
    },
    style green/.style={
      set fill color=mygreen,
      set border color=white,
    },
    style blue/.style={
      set fill color=myblue,
      set border color=white,
    },
    style orange/.style={
      set fill color=myorange,
      set border color=white,
    },
    style cyan/.style={
      set fill color=mycyan,
      set border color=white,
    },
    style magenta/.style={
      set fill color=mymagenta,
      set border color=white,
    },
    %
    hor/.style={
      above left offset={-0.15,0.31},
      below right offset={0.15,-0.125},
      #1
    },
    ver/.style={
      above left offset={-0.1,0.3},
      below right offset={0.15,-0.15},
      #1
    }
  }
'''

Makefile

# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS    ?=
SPHINXBUILD   ?= sphinx-build
SOURCEDIR     = source
BUILDDIR      = build

# Put it first so that "make" without argument is like "make help".
help:
    @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
    @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

make.bat

@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
    set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
    echo.
    echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
    echo.installed, then set the SPHINXBUILD environment variable to point
    echo.to the full path of the 'sphinx-build' executable. Alternatively you
    echo.may add the Sphinx directory to PATH.
    echo.
    echo.If you don't have Sphinx installed, grab it from
    echo.http://sphinx-doc.org/
    exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd

EDIT: Added makefile used to build the rst’s


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.