Commit 71847dc1 authored by Pierre Augier's avatar Pierre Augier

Version 0.2.3 with fluiddoc.mathmacro

parent f0a41e4b3ee0
......@@ -2,6 +2,8 @@
The main contributors are:
- Pierre Augier (LEGI, CNRS, UGA)
- Cyrille Bonamy (LEGI, CNRS, UGA)
- Ashwin Vishnu (KTH)
- Cyrille Bonamy (LEGI, CNRS, UGA)
- Antoine Campagne (LEGI, CNRS)
- Julien Salort (Laboratoire de physique, ENS de Lyon)
- Miguel Calpe Linares (LEGI, CNRS)
0.2.3
-----
- ``fluiddoc.mathmacro``.
- More fft (get_seq_indices_first_X, fftw_grid_size).
- Better test coverage and less bugs.
- ``fluidcluster-help``.
- Better ``fluidinfo``.
0.2.2
-----
......
......@@ -3,6 +3,19 @@
Advice for FluidDyn developers
==============================
- Discussions on the development of the FluidDyn packages take place in the
`FluidDyn developer chat room
<https://riot.im/app/#/room/#fluiddyn-dev:matrix.org>`_.
- Use a text editor with flake8 enabled (see for example `our emacs setup
<https://bitbucket.org/fluiddyn/fluid_emacs.d>`_).
- Use the Python code formatter `black <https://github.com/ambv/black>`_ with the
command ``make black``.
- Run the unittests before committing.
Mercurial
---------
Fluiddyn has been designed to be used by scientists-developers. Thus, you may
have to modify the code of the FluidDyn packages. So I would advice to work
"as a developer", i.e. to get the source code and to use revision control and
......@@ -20,6 +33,8 @@ and Bitbucket, you can also read this short tutorial:
mercurial_bitbucket
fluiddevops: a tool to handle the FluidDyn repositories
-------------------------------------------------------
We present a tool to handle the different FluidDyn repositories.
......
......@@ -22,8 +22,6 @@ from fluiddoc.ipynb_maker import ipynb_to_rst
mock_modules(('nbstripout',))
import fluiddoc.fluidnbstripout
ipynb_to_rst()
ipynb_to_rst('ipynb/executed', executed=True)
......@@ -45,11 +43,10 @@ sys.path.insert(0, os.path.abspath('./'))
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.doctest',
'sphinx.ext.todo',
# 'sphinx.ext.pngmath',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode', 'sphinx.ext.autosummary',
'numpydoc',
'mathmacro',
'fluiddoc.mathmacro',
]
# Add any paths that contain templates here, relative to this directory.
......
......@@ -73,10 +73,13 @@ More
:maxdepth: 1
FluidDyn forge in Bitbucket <https://bitbucket.org/fluiddyn/fluiddyn>
FluidDyn in PyPI <https://pypi.python.org/pypi/fluiddyn/>
FluidDyn in PyPI <https://pypi.org/project/fluiddyn/>
to_do
changes
authors
FluidDyn blog <https://fluiddyn.bitbucket.io/>
FluidDyn developer chat room <https://riot.im/app/#/room/#fluiddyn-dev:matrix.org>
FluidDyn user chat room <https://riot.im/app/#/room/#fluiddyn-users:matrix.org>
Indices and tables
......
To do list
==========
FluidDyn is still in a planning stage so there is still A LOT to do!!
..
Long term
---------
Long term
---------
- VAPOR is the Visualization and Analysis Platform for Ocean,
Atmosphere, and Solar Researchers (https://www.vapor.ucar.edu/)
- Library for 2D pencil decomposition and distributed Fast Fourier
Transform: http://www.2decomp.org
- VisIt is a free [and open-source], interactive parallel
visualization and graphical analysis tool
(https://wci.llnl.gov/simulation/computer-codes/visit)
- Parallel Three-Dimensional Fast Fourier Transforms:
https://code.google.com/p/p3dfft/
- VAPOR is the Visualization and Analysis Platform for Ocean,
Atmosphere, and Solar Researchers (https://www.vapor.ucar.edu/)
- VisIt is a free [and open-source], interactive parallel
visualization and graphical analysis tool
(https://wci.llnl.gov/simulation/computer-codes/visit)
- interface for `Arduino boards <http://arduino.cc/>`_ (see also `on
wikipedia <http://en.wikipedia.org/wiki/Arduino>`_ and the Python
module `Arduino
<https://github.com/thearn/Python-Arduino-Command-API>`_).
Questions
---------
- String, unicode and byte in Python 2 and 3.
- interface for `Arduino boards <http://arduino.cc/>`_ (see also `on
wikipedia <http://en.wikipedia.org/wiki/Arduino>`_ and the Python
module `Arduino
<https://github.com/thearn/Python-Arduino-Command-API>`_).
Inline to do items
......
......@@ -16,6 +16,7 @@ by Readthedocs (by the way, thank you to the readthedocs people!).
ipynb_maker
fluidnbstripout
fluiddocset
mathmacro
"""
......@@ -44,13 +45,13 @@ def mock_modules(modules):
Examples
--------
.. code-block:: python
mock_modules((
'h5py', 'h5netcdf', 'pyfftw', 'theano',
'reikna.cluda', 'reikna.fft', 'reikna.transformations'))
"""
......
......@@ -72,9 +72,7 @@ def main():
# Big change compared to original nbstripout! :-)
if not args.no_exclude_nbconvert:
filenames = [
filename
for filename in filenames
if not filename.endswith(".nbconvert.ipynb")
fname for fname in filenames if not fname.endswith(".nbconvert.ipynb")
]
for filename in filenames:
......
"""Sphinx extension provide a new directive *mathmacro*.
r"""Sphinx extension providing a new directive ``mathmacro``
============================================================
This extension has to be added after the other math extension since it
redefined the math directive and the math role. For example, like this
......@@ -6,10 +7,67 @@ redefined the math directive and the math role. For example, like this
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.doctest',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode', 'sphinx.ext.autosummary',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode', 'sphinx.ext.autosummary',
'numpydoc',
'mathmacro']
'fluiddoc.mathmacro']
Here, I show how to use a new mathmacro substitution directive in
reStructuredText. I think even this small example demonstrates that it
is useful.
Example
-------
First some math without math macros. Let's take the example of the incompressible
Navier-Stokes equation:
.. math::
\mbox{D}_t \textbf{v} =
-\boldsymbol{\nabla} p + \nu \boldsymbol{\nabla} ^2 \textbf{v}.
where :math:`\mbox{D}_t` is the convective derivative, :math:`\textbf{v}` the
velocity, :math:`\boldsymbol{\nabla}` the nabla operator, :math:`\nu` the
viscosity and :math:`\boldsymbol{\nabla}^2` the Laplacian operator.
The code for this is:
.. code-block:: rest
.. math::
\mbox{D}_t \textbf{v} =
-\boldsymbol{\nabla} p + \nu \boldsymbol{\nabla} ^2 \textbf{v}.
where :math:`\mbox{D}_t` is the convective derivative, :math:`\textbf{v}` the
velocity, :math:`\boldsymbol{\nabla}` the nabla operator, :math:`\nu` the
viscosity and :math:`\boldsymbol{\nabla}^2` the Laplacian operator.
.. |Dt| mathmacro:: \mbox{D}_t
.. |bnabla| mathmacro:: \boldsymbol{\nabla}
.. |vv| mathmacro:: \textbf{v}
Now, let's use some math macros and try to get the same result... We use the
following code:
.. code-block:: rest
The Navier-Stokes equation can now be written like this:
.. math:: \Dt \vv = - \bnabla p + \nu \bnabla^2 \vv
where |Dt| is the convective derivative, |vv| the velocity, |bnabla| the nabla
operator, :math:`\nu` the viscosity and :math:`\bnabla^2` the Laplacian operator.
It gives:
The Navier-Stokes equation can now be written like this:
.. math:: \Dt \vv = - \bnabla p + \nu \bnabla^2 \vv
where |Dt| is the convective derivative, |vv| the velocity, |bnabla| the nabla
operator, :math:`\nu` the viscosity and :math:`\bnabla^2` the Laplacian operator.
"""
......@@ -30,18 +88,26 @@ def multiple_replacer(replace_dict):
`replace_dict.values`, respectively.
"""
def replacement_function(match):
s = match.group(0)
end = s[-1]
if re.match(r'[\W_]', end):
return replace_dict[s[:-1]]+end
if re.match(r"[\W_]", end):
return replace_dict[s[:-1]] + end
else:
return replace_dict[s]
pattern = "|".join([re.escape(k)+r'[\W_]'
for k in replace_dict.keys()])
pattern = "|".join(
[re.escape(k) + r"[\W_$]" for k in replace_dict.keys()]
+ [re.escape(k) + '$' for k in replace_dict.keys()]
)
pattern = re.compile(pattern, re.M)
return lambda string: pattern.sub(replacement_function, string)
def _mreplace(string):
return pattern.sub(replacement_function, string)
return _mreplace
def multiple_replace(string, replace_dict):
mreplace = multiple_replacer(replace_dict)
......@@ -50,21 +116,23 @@ def multiple_replace(string, replace_dict):
class MathMacro(Replace):
"""Directive defining a math macro."""
def run(self):
if not hasattr(self.state.document, 'math_macros'):
if not hasattr(self.state.document, "math_macros"):
self.state.document.math_macros = {}
latex_key = '\\'+self.state.parent.rawsource.split('|')[1]
self.state.document.math_macros[latex_key] = ''.join(self.content)
latex_key = "\\" + self.state.parent.rawsource.split("|")[1]
self.state.document.math_macros[latex_key] = "".join(self.content)
self.content[0] = ':math:`'+self.content[0]
self.content[-1] = self.content[-1]+'`'
self.content[0] = ":math:`" + self.content[0]
self.content[-1] = self.content[-1] + "`"
return super(MathMacro, self).run()
class NewMathDirective(MathDirective):
"""New math block directive parsing the latex code."""
def run(self):
try:
math_macros = self.state.document.math_macros
......@@ -72,16 +140,15 @@ class NewMathDirective(MathDirective):
pass
else:
if math_macros:
multiple_replace = multiple_replacer(math_macros)
mreplace = multiple_replacer(math_macros)
for i, c in enumerate(self.content):
self.content[i] = multiple_replace(c)
self.content[i] = mreplace(c)
for i, a in enumerate(self.arguments):
self.arguments[i] = multiple_replace(a)
self.arguments[i] = mreplace(a)
return super(NewMathDirective, self).run()
def new_math_role(role, rawtext, text, lineno, inliner,
options={}, content=[]):
def new_math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
"""New math role parsing the latex code."""
try:
math_macros = inliner.document.math_macros
......@@ -90,14 +157,28 @@ def new_math_role(role, rawtext, text, lineno, inliner,
else:
if math_macros:
rawtext = multiple_replace(rawtext, math_macros)
text = rawtext.split('`')[1]
text = rawtext.split("`")[1]
return math_role(role, rawtext, text, lineno, inliner,
options=options, content=content)
return math_role(
role, rawtext, text, lineno, inliner, options=options, content=content
)
def setup(app):
app.add_role('math', new_math_role)
app.add_directive('math', NewMathDirective)
app.add_directive('mathmacro', MathMacro)
# when sphinx 1.8 is available, we can add the argument override=True to
# add_role and add_directive to avoid warnings...
try:
# sphinx 1.8
app.add_role("math", new_math_role, override=True)
app.add_directive("math", NewMathDirective, override=True)
except TypeError:
app.add_role("math", new_math_role)
app.add_directive("math", NewMathDirective)
app.add_directive("mathmacro", MathMacro)
if __name__ == '__main__':
math_macros = {'\\vv': '\\textbf{v}'}
s = '\\vv'
mreplace = multiple_replacer(math_macros)
print(mreplace(s))
......@@ -11,4 +11,4 @@ http://legacy.python.org/dev/peps/pep-0386/
'a' or 'alpha' means alpha version (internal testing),
'b' or 'beta' means beta version (external testing).
"""
__version__ = "0.2.2"
__version__ = "0.2.3"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment