From ed82434c2ae77e09b16383345317c071e9c0faaf Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Mon, 11 Feb 2019 10:19:33 +0100 Subject: [PATCH] Fix LaTeX math definitions An alternative to #80 and #81. --- doc/conf.py | 21 ++++++++++++++++++++- doc/math-definitions.rst | 10 ---------- sfs/mono/drivingfunction.py | 7 +------ sfs/time/drivingfunction.py | 6 +----- sfs/time/source.py | 2 -- sfs/util.py | 7 +------ 6 files changed, 23 insertions(+), 30 deletions(-) delete mode 100644 doc/math-definitions.rst diff --git a/doc/conf.py b/doc/conf.py index 81003bf3..1842293d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -149,6 +149,25 @@ # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False +math_definitions = r""" +\newcommand{\dirac}[1]{\operatorname{\delta}\left(#1\right)} +\newcommand{\e}[1]{\operatorname{e}^{#1}} +\newcommand{\Hankel}[3]{\mathop{{}H_{#2}^{(#1)}}\!\left(#3\right)} +\newcommand{\hankel}[3]{\mathop{{}h_{#2}^{(#1)}}\!\left(#3\right)} +\renewcommand{\i}{\mathrm{i}} +\newcommand{\scalarprod}[2]{\left\langle#1,#2\right\rangle} +\renewcommand{\vec}[1]{\mathbf{#1}} +\newcommand{\wc}{\frac{\omega}{c}} +""" + +rst_prolog = """ +.. only:: html + + .. rst-class:: hidden + .. math:: + + """ + ' '.join(math_definitions.split('\n')) + # -- Options for HTML output ---------------------------------------------- @@ -251,7 +270,7 @@ def setup(app): #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. -#'preamble': '', +'preamble': math_definitions, 'printindex': '', } diff --git a/doc/math-definitions.rst b/doc/math-definitions.rst deleted file mode 100644 index ee88d288..00000000 --- a/doc/math-definitions.rst +++ /dev/null @@ -1,10 +0,0 @@ -.. rst-class:: hidden -.. math:: - \newcommand{\dirac}[1]{\operatorname{\delta}\left(#1\right)} - \newcommand{\e}[1]{\operatorname{e}^{#1}} - \newcommand{\Hankel}[3]{\mathop{{}H_{#2}^{(#1)}}\!\left(#3\right)} - \newcommand{\hankel}[3]{\mathop{{}h_{#2}^{(#1)}}\!\left(#3\right)} - \newcommand{\i}{\mathrm{i}} - \newcommand{\scalarprod}[2]{\left\langle#1,#2\right\rangle} - \renewcommand{\vec}[1]{\mathbf{#1}} - \newcommand{\wc}{\frac{\omega}{c}} diff --git a/sfs/mono/drivingfunction.py b/sfs/mono/drivingfunction.py index af7f3df7..cad6ea03 100644 --- a/sfs/mono/drivingfunction.py +++ b/sfs/mono/drivingfunction.py @@ -1,9 +1,4 @@ -"""Compute driving functions for various systems. - -.. include:: math-definitions.rst - -""" - +"""Compute driving functions for various systems.""" import numpy as np from numpy.core.umath_tests import inner1d # element-wise inner product from scipy.special import jn, hankel2 diff --git a/sfs/time/drivingfunction.py b/sfs/time/drivingfunction.py index a4e5c281..fb624b04 100644 --- a/sfs/time/drivingfunction.py +++ b/sfs/time/drivingfunction.py @@ -1,8 +1,4 @@ -"""Compute time based driving functions for various systems. - -.. include:: math-definitions.rst - -""" +"""Compute time based driving functions for various systems.""" import numpy as np from numpy.core.umath_tests import inner1d # element-wise inner product from .. import defs diff --git a/sfs/time/source.py b/sfs/time/source.py index 994e15f4..92d3ac8c 100644 --- a/sfs/time/source.py +++ b/sfs/time/source.py @@ -2,8 +2,6 @@ The Green's function describes the spatial sound propagation over time. -.. include:: math-definitions.rst - """ import numpy as np diff --git a/sfs/util.py b/sfs/util.py index f91c4a6a..1c449857 100644 --- a/sfs/util.py +++ b/sfs/util.py @@ -1,9 +1,4 @@ -"""Various utility functions. - -.. include:: math-definitions.rst - -""" - +"""Various utility functions.""" import collections import numpy as np from scipy.special import spherical_jn, spherical_yn