From 1561cf50a1758d233b78b82e48bc5d0ea320c1b6 Mon Sep 17 00:00:00 2001 From: Matthias Baumann Date: Mon, 25 Jan 2021 17:02:31 +0100 Subject: [PATCH] New package circuitikz; addresses #158 --- HISTORY.md | 2 ++ list-of-macros.md | 21 ++++++++++++ tests/test_packages/test_circuitikz.py | 44 ++++++++++++++++++++++++++ yalafi/packages/circuitikz.py | 29 +++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 tests/test_packages/test_circuitikz.py create mode 100644 yalafi/packages/circuitikz.py diff --git a/HISTORY.md b/HISTORY.md index 3fa2fd05..71e6d170 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,8 @@ Work in progress (PR [#162](../../pull/162)) - macros \\setmathfont, \\unimathsetup - unicode math operators + - new package circuitikz: environment circuitikz + (issue [#158](../../issues/158)) - package amsthm: added macro \\newtheoremstyle; **thanks to @torik42** (PR [#164](../../pull/164)) - package babel diff --git a/list-of-macros.md b/list-of-macros.md index a664d697..5a1f3803 100644 --- a/list-of-macros.md +++ b/list-of-macros.md @@ -16,6 +16,7 @@ Please note that not everything has to be declared. [amsthm](#package-amsthm), [babel](#package-babel), [biblatex](#package-biblatex), +[circuitikz](#package-circuitikz), [geometry](#package-geometry), [glossaries](#package-glossaries), [glossaries-extra](#package-glossaries-extra), @@ -201,6 +202,26 @@ tests: [tests/test\_packages/test\_biblatex.py](tests/test_packages/test_biblate \\printbibliography +## Package circuitikz + +Source: [yalafi/packages/circuitikz.py](yalafi/packages/circuitikz.py), +tests: [tests/test\_packages/test\_circuitikz.py](tests/test_packages/test_circuitikz.py) + +We simply remove the circuit in environment 'circuitikz'. + +**Loaded packages** + +[tikz](#package-tikz) + +**Macros** + +\\ctikzset + +**Environments** + +circuitikz + + ## Package geometry Source: [yalafi/packages/geometry.py](yalafi/packages/geometry.py), diff --git a/tests/test_packages/test_circuitikz.py b/tests/test_packages/test_circuitikz.py new file mode 100644 index 00000000..89eff6a5 --- /dev/null +++ b/tests/test_packages/test_circuitikz.py @@ -0,0 +1,44 @@ + + +import pytest +from yalafi import parameters, parser, utils + +preamble = '\\usepackage{circuitikz}\n' + +def get_plain(latex): + parms = parameters.Parameters() + p = parser.Parser(parms) + plain, nums = utils.get_txt_pos(p.parse(preamble + latex)) + assert len(plain) == len(nums) + return plain + + +data_test_macros_latex = [ + + (r'A\ctikzset{X}B', 'AB'), + (r'A\usetikzlibrary XB', 'AB'), + ( +r""" +A +\begin{circuitikz} + \ctikzset{voltage/bump b/.initial=0} % defines arrow's curvature + \draw (0,3) to[short,o-*] (1,3) -- (1,3.5) to[R,l=$R$] (4,3.5) to[L=$L$] (7,3.5) -- (7,3) to[short,i=$I_{Last}$,*-] (9,3) + to[R,l=$R_{Last}$] (9,0) to[short,-o] (0,0); + \draw (1,3) -- (1,2.5) to[C,l_=$C$] (7,2.5) -- (7,3); + \draw (0,3) to[open,v=$U_e$] (0,0); +\end{circuitikz} +B +""", +r""" +A +B +""" + ), + +] + +@pytest.mark.parametrize('latex,plain_expected', data_test_macros_latex) +def test_macros_latex(latex, plain_expected): + plain = get_plain(latex) + assert plain == plain_expected + diff --git a/yalafi/packages/circuitikz.py b/yalafi/packages/circuitikz.py new file mode 100644 index 00000000..c7479363 --- /dev/null +++ b/yalafi/packages/circuitikz.py @@ -0,0 +1,29 @@ + +# +# YaLafi module for LaTeX package circuitikz +# + +from yalafi.defs import Environ, InitModule + +require_packages = ['tikz'] + +def init_module(parser, options): + parms = parser.parms + + macros_latex = r""" + + \newcommand{\ctikzset}[1]{} + + """ + + macros_python = [] + + environments = [ + + Environ(parms, 'circuitikz', remove=True, add_pars=False), + + ] + + return InitModule(macros_latex=macros_latex, macros_python=macros_python, + environments=environments) +