Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial minted support #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions list-of-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Please note that not everything has to be declared.
[inputenc](#package-inputenc),
[listings](#package-listings),
[mathtools](#package-mathtools),
[minted](#package-minted),
[pgfplots](#package-pgfplots),
[tikz](#package-tikz),
[unicode-math](#package-unicode-math),
Expand Down Expand Up @@ -397,6 +398,19 @@ tests: [tests/test\_packages/test\_mathtools.py](tests/test_packages/test_mathto

\\mathtoolsset

## Package minted

Source: [yalafi/packages/minted.py](yalafi/packages/minted.py),
tests: [tests/test\_packages/test\_minted.py](tests/test_packages/test_minted.py)

**Macros**

\\setminted
\\mintinline

**Environments**

minted

## Package pgfplots

Expand Down
39 changes: 39 additions & 0 deletions tests/test_packages/test_minted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


import pytest
from yalafi import parameters, parser, utils

preamble = '\\usepackage{minted}\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\setminted{opts}B', 'AB'),
(r'A\mintinline{lang}{code}B', 'AB'),

]

@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


data_test_environments = [

(r'A\begin{minted}{prolog}[opts]code\end{minted}B', 'A\n\n\nB'),

]

@pytest.mark.parametrize('latex,plain_expected', data_test_environments)
def test_environments(latex, plain_expected):
plain = get_plain(latex)
assert plain == plain_expected

1 change: 1 addition & 0 deletions yalafi/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'inputenc',
'listings',
'mathtools',
'minted',
'pgfplots',
'subfiles',
'tikz',
Expand Down
30 changes: 30 additions & 0 deletions yalafi/packages/minted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#
# YaLafi module for LaTeX package minted
#

from yalafi.defs import InitModule, Environ

require_packages = []

def init_module(parser, options, position):
parms = parser.parms

macros_latex = r"""

\newcommand{\setminted}[1]{}
\newcommand{\mintinline}[2]{}

"""

macros_python = []

environments = [

Environ(parms, 'minted', remove=True),

]

return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)