Skip to content

Commit

Permalink
FIXED: Fix unnecessary underscore escaping in LaTeX (Fixes #250)
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcher committed Jun 17, 2023
1 parent 331977b commit 2e99736
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/latex.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ void mmd_print_string_latex(DString * out, const char * str) {
}


void mmd_print_label_latex(DString * out, const char * str) {
if (str == NULL) {
return;
}

while (*str != '\0') {
if (*str == '_') {
print_char(*str);
} else {
mmd_print_char_latex(out, *str);
}

str++;
}
}


void mmd_print_localized_char_latex(DString * out, unsigned short type, scratch_pad * scratch) {
switch (type) {
case DASH_N:
Expand Down Expand Up @@ -272,18 +289,18 @@ void mmd_export_link_latex(DString * out, const char * source, token * text, lin
if (temp_char && temp_char[0] != '\0') {
mmd_export_token_tree_latex(out, source, text->child, scratch);
print_const(" (\\autoref{");
mmd_print_string_latex(out, &(link->url)[1]);
mmd_print_label_latex(out, &(link->url)[1]);
print_const("})");
} else {
print_const("\\autoref{");
mmd_print_string_latex(out, &(link->url)[1]);
mmd_print_label_latex(out, &(link->url)[1]);
print_const("}");
}

free(temp_char);
} else {
print_const("\\autoref{");
mmd_print_string_latex(out, &(link->url)[1]);
mmd_print_label_latex(out, &(link->url)[1]);
print_const("}");
}

Expand Down
4 changes: 4 additions & 0 deletions tests/MMD6Tests/Cross-References.fodt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ office:mimetype="application/vnd.oasis.opendocument.text">
<text:h text:outline-level="1"><text:bookmark text:name="test的multibyte"/>Test 的 Multibyte</text:h>

<text:p text:style-name="Standard">10</text:p>

<text:h text:outline-level="1"><text:bookmark text:name="test_underscore"/>Test_Underscore</text:h>

<text:p text:style-name="Standard">Link to <text:a xlink:type="simple" xlink:href="#test_underscore">Test_Underscore</text:a>.</text:p>
</office:text>
</office:body>
</office:document>
4 changes: 4 additions & 0 deletions tests/MMD6Tests/Cross-References.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ <h1 id="test的multibyte">Test 的 Multibyte</h1>

<p>10</p>

<h1 id="test_underscore">Test_Underscore</h1>

<p>Link to <a href="#test_underscore">Test_Underscore</a>.</p>

</body>
</html>

4 changes: 4 additions & 0 deletions tests/MMD6Tests/Cross-References.htmlc
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ latexconfig: article</p>
<h1>Test 的 Multibyte</h1>

<p>10</p>

<h1>Test_Underscore</h1>

<p>Link to [Test_Underscore].</p>
3 changes: 2 additions & 1 deletion tests/MMD6Tests/Cross-References.opml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<outline text="Strip out &amp;%^ characters &amp;*^" _note="&#10;[A Section].&#10;&#10;"><outline text="1 Cross-References: Special Characters!@#$%&amp;*()&lt;&gt;^" _note="&#10;5&#10;&#10;And now, link to [1 Cross-References: Special Characters!@#$%&amp;*()&lt;&gt;^][]&#10;&#10;"></outline>
</outline>
<outline text="Заголовок по-русски" _note="&#10;И ссылка на [Заголовок по-русски].&#10;&#10;"></outline>
<outline text="Test 的 Multibyte" _note="&#10;10&#10;"></outline>
<outline text="Test 的 Multibyte" _note="&#10;10&#10;&#10;"></outline>
<outline text="Test_Underscore" _note="&#10;Link to [Test_Underscore].&#10;"></outline>
<outline text="&gt;&gt;Metadata&lt;&lt;">
<outline text="title" _note="Cross-References"/>
<outline text="latexconfig" _note="article"/>
Expand Down
5 changes: 5 additions & 0 deletions tests/MMD6Tests/Cross-References.tex
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ \part{Test 的 Multibyte}

10

\part{Test\_Underscore}
\label{test_underscore}

Link to Test\_Underscore (\autoref{test_underscore}).

\input{mmd6-article-footer}
\end{document}
4 changes: 4 additions & 0 deletions tests/MMD6Tests/Cross-References.text
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ And now, link to [1 Cross-References: Special Characters!@#$%&*()<>^][]
# Test 的 Multibyte #

10

# Test_Underscore #

Link to [Test_Underscore].

0 comments on commit 2e99736

Please sign in to comment.