示例#1
0
def test_extract_bibitem_tokens_from_curly_braces():
    tex = "\n".join(["\\bibitem[label]{key1}", "token1 {token2} {token3}",])
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 1
    assert bibitems[0].id_ == "key1"
    assert bibitems[0].text == "token1 token2 token3"
示例#2
0
def test_extract_bibitem_include_hyperref_contents():
    tex = "\n".join(
        ["\\bibitem[label]{key1}", r"token1 \href{https://url.com}{token2}"])
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 1
    assert bibitems[0].text == "token1 token2"
示例#3
0
def test_extract_bibitem_stop_at_newline():
    tex = "\n".join(
        ["\\bibitem[label]{key1}", "token1", "", "text after bibliography (to ignore)"]
    )
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 1
    assert bibitems[0].id_ == "key1"
    assert bibitems[0].text == "token1"
示例#4
0
def test_extract_bibitems_from_environment():
    tex = "\n".join([
        "\\begin{thebibliography}",
        "\\bibitem[label]{key1}",
        "token1",
        "\\end{thebibliography}",
    ])
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 1
    assert bibitems[0].id_ == "key1"
    assert bibitems[0].text == "token1"
示例#5
0
def test_extract_bibitems():
    tex = "\n".join([
        "\\bibitem[label]{key1}",
        "token1",
        "\\newblock \\emph{token2}",
        "\\newblock token3",
        "\\bibitem[label]{key2}",
        "token4",
        "\\newblock \\emph{token5}",
    ])
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 2
    assert bibitems[0].id_ == "key1"
    assert bibitems[0].text == "token1 token2 token3"
    assert bibitems[1].id_ == "key2"
    assert bibitems[1].text == "token4 token5"
示例#6
0
def test_extract_bibitem_with_brackets_in_label():
    tex = "\n".join([r"\bibitem[label{[]}]{key}", r"token"])
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 1
    assert "token" in bibitems[0].text
示例#7
0
def test_extract_bibitem_wrapping_key():
    tex = "\n".join([r"\bibitem[label]%", r"    {key}", r"    token"])
    extractor = BibitemExtractor()
    bibitems = list(extractor.parse(tex))
    assert len(bibitems) == 1
    assert "token" in bibitems[0].text