Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_numbering_latex():
init()
src = Para(createListStr(u'Exercise #'))
dest = Para([
RawInline(u'tex', u'\\phantomsection\\addcontentsline{exercise}{exercise}{\\protect\\numberline {1}{\\ignorespaces Exercise}}'),
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[RawInline('tex', '\\label{exercise:1}'), Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], 'latex', {}) == dest
init()
src = Para(createListStr(u'Exercise (The title) #'))
dest = Para([
RawInline(u'tex', u'\\phantomsection\\addcontentsline{exercise}{exercise}{\\protect\\numberline {1}{\\ignorespaces The title}}'),
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[
RawInline('tex', '\\label{exercise:1}'),
Strong(createListStr(u'Exercise 1')),
Space(),
def test_numbering_latex():
init()
src = Para(createListStr(u'Exercise #'))
dest = Para([
RawInline(u'tex', u'\\phantomsection\\addcontentsline{exercise}{exercise}{\\protect\\numberline {1}{\\ignorespaces Exercise}}'),
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[RawInline('tex', '\\label{exercise:1}'), Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], 'latex', {}) == dest
init()
src = Para(createListStr(u'Exercise (The title) #'))
dest = Para([
RawInline(u'tex', u'\\phantomsection\\addcontentsline{exercise}{exercise}{\\protect\\numberline {1}{\\ignorespaces The title}}'),
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[
return RawInline('latex', r"\end{thebibliography}")
if re.search("@bibitem", value):
title, desc, date, url = value.split(":", 1)[1].split(", ")
inline = r"\bibitem{" + title + "} " + desc
inline += r" \textsl{" + date + "}."
inline2 = 'latex', r"\url{" + url + "}"
type_ = 'latex'
return [RawInline(type_, inline), LineBreak(), RawInline(inline2)]
elif key == 'Image':
[attrs, caption, src] = value
new_capt = src[0]
# add \label{IMAGE_LABEL} to the picture description
new_desc = "\\" + "label{" + new_capt + "}"
caption.append(RawInline('latex', new_desc))
return Image(attrs, caption, src)
prefix += ' '
label = citation['citationId']
if label not in self.references:
return
rtype = self.references[label]['type']
n = self.references[label]['id']
text = self.replacements[rtype].format(n)
if format == 'latex' and self.autoref:
link = u'{pre}\\autoref{{{label}}}{post}'.format(pre=prefix,
label=label,
post=suffix)
return pf.RawInline('latex', link)
elif format == 'latex' and not self.autoref:
link = u'{pre}\\ref{{{label}}}{post}'.format(pre=prefix,
label=label,
post=suffix)
return pf.RawInline('latex', link)
else:
link_text = '{}{}{}'.format(prefix, text, suffix)
link = pf.Link([pf.Str(link_text)], ('#' + label, ''))
return link
def ilatex(x):
return RawInline('tex', x)
"""
Filter datas.
First part search for latex reference to figure and writes them
as RawInline thereby backslashes are not escaped. It also removes
the extra $ symbols.
Second part search for images and set a label in the description
in order to be able to make a reference to them.
"""
if key == 'Str':
if re.search(r"$ref.*$", value):
# if we find a link, set it as raw link and re-add a
# backslash before the ref keyword and remote
value = value.replace("$", "")
val = RawInline('latex', "\\" + value)
return val
if key == 'Image':
[attrs, caption, src] = value
# this means the image label hasn't been modified yet
# (the mardown file doesn't come from a rst file)
if caption[-1]['t'] != 'RawInline':
new_capt = src[0]
# add \label{IMAGE_LABEL} to the picture description
new_desc = "\\" + "label{" + new_capt + "}"
caption.append(RawInline('latex', new_desc))
return Image(attrs, caption, src)
def ilatex(x):
return RawInline('tex', x)
(' ' if eq['is_unreferenceable'] else
' id="%s" '%attrs.id))
inner = RawInline('html', '<span class="eqnos-number">')
eqno = Math({"t":"InlineMath"}, '(%s)' % num[1:-1]) \
if num.startswith('$') and num.endswith('$') \
else Str('(%s)' % num)
endtags = RawInline('html', '</span>')
ret = [outer, AttrMath(*value), inner, eqno, endtags]
elif fmt == 'docx':
# As per http://officeopenxml.com/WPhyperlink.php
bookmarkstart = \
RawInline('openxml',
''
%attrs.id)
bookmarkend = \
RawInline('openxml',
'')
ret = [bookmarkstart, AttrMath(*value), bookmarkend]
return ret
elif fmt in ['latex', 'beamer']:
ret = RawInline('tex',
r'\begin{equation}%s\end{equation}'%value[-1])
elif fmt in ('html', 'html5', 'epub', 'epub2', 'epub3') and \
LABEL_PATTERN.match(attrs.id):
# Present equation and its number in a span
num = str(references[attrs.id].num)
outer = RawInline('html',
'' % \
(' ' if eq['is_unreferenceable'] else
' id="%s" '%attrs.id))
inner = RawInline('html', '<span class="eqnos-number">')
eqno = Math({"t":"InlineMath"}, '(%s)' % num[1:-1]) \
if num.startswith('$') and num.endswith('$') \
else Str('(%s)' % num)
endtags = RawInline('html', '</span>')
ret = [outer, AttrMath(*value), inner, eqno, endtags]
elif fmt == 'docx':
# As per http://officeopenxml.com/WPhyperlink.php
bookmarkstart = \
RawInline('openxml',
''
%attrs.id)
bookmarkend = \
RawInline('openxml',
'')
ret = [bookmarkstart, AttrMath(*value), bookmarkend]
return ret
def inlatex(s):
return pf.RawInline('latex', s)