Skip to content

Commit

Permalink
Merge pull request #166 from matze-dd/Circuitikz
Browse files Browse the repository at this point in the history
New package circuitikz; addresses #158
  • Loading branch information
matze-dd authored Jan 25, 2021
2 parents e1df095 + 1561cf5 commit dabb131
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions list-of-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
44 changes: 44 additions & 0 deletions tests/test_packages/test_circuitikz.py
Original file line number Diff line number Diff line change
@@ -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

29 changes: 29 additions & 0 deletions yalafi/packages/circuitikz.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit dabb131

Please sign in to comment.