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

[latex writer] dollar character should not be escaped in LaTeX \url{} links #1913

Closed
dwwalker opened this issue Jan 30, 2015 · 1 comment
Closed

Comments

@dwwalker
Copy link

In Text/Pandoc/Writers/LaTeX.hs dollar signs ($) are escaped by the following line:

'$' -> "\\$" ++ rest

This is correct for body text, where text like "$100" will be converted to the escaped form: "\$100". However, this is wrong for links that will be inside \url{} functions, because the url package performs the escaping for $ itself. Dollar signs are rare, but still valid inside URLs. Domino servers tend to rely on them in forming many URLs. For example, consider the following markdown:

<https://10.85.1.101/baz/qux.nsf/$about?OpenAbout>

This will produce the following latex:

\url{https://10.85.1.101/baz/qux.nsf/\$about?OpenAbout}

This will compile with latex without showing any errors, but the final output text will be wrong. The link text will appear like this: https://10.85.1.101/baz/qux.nsf/\protect\T1\textdollarabout?OpenAbout

Proposed Change

Add the not isUrl condition to the dollar character, the same as is done for underscores, hyphens and others. Change line 209 as follows:

--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -206,7 +206,7 @@ stringToLaTeX  ctx (x:xs) = do
        '€' -> "\\euro{}" ++ rest
        '{' -> "\\{" ++ rest
        '}' -> "\\}" ++ rest
-       '$' -> "\\$" ++ rest
+       '$' | not isUrl -> "\\$" ++ rest
        '%' -> "\\%" ++ rest
        '&' -> "\\&" ++ rest
        '_' | not isUrl -> "\\_" ++ rest

This change has been tested with pandoc 1.13.3. and produces the desired output for URL links when converting to LaTeX.

@jgm
Copy link
Owner

jgm commented Jan 30, 2015

Looks good to me. If it's convenient to submit a pull
request with this change, that would be helpful.

+++ dwwalker [Jan 29 15 23:06 ]:

In Text/Pandoc/Writers/LaTeX.hs dollar signs ($) are escaped by the
following line:

'$' -> "$" ++ rest

This is correct for body text, where text like "$100" will be converted
to the escaped form: "$100". However, this is wrong for links that
will be inside \url{} functions, because the url package performs the
escaping for $ itself. Dollar signs are rare, but still valid inside
URLs. Domino servers tend to rely on them in forming many URLs. For
example, consider the following markdown:

https://10.85.1.101/baz/qux.nsf/$about?OpenAbout

This will produce the following latex:

\url{https://10.85.1.101/baz/qux.nsf/\$about?OpenAbout}

This will compile with latex without showing any errors, but the final
output text will be wrong. The link text will appear like this:
https://10.85.1.101/baz/qux.nsf/\protect\T1\textdollarabout?OpenAbout

Proposed Change

Add the not isUrl condition to the dollar character, the same as is
done for underscores, hyphens and others. Change line 209 as follows:

--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -206,7 +206,7 @@ stringToLaTeX ctx (x:xs) = do
'€' -> "\euro{}" ++ rest
'{' -> "{" ++ rest
'}' -> "}" ++ rest

  •   '$' -> "\$" ++ rest
    
  •   '$' | not isUrl -> "\\$" ++ rest
    

    '%' -> "%" ++ rest
    '&' -> "&" ++ rest
    '_' | not isUrl -> "_" ++ rest

    This change has been tested with pandoc 1.13.3. and produces the
    desired output for URL links when converting to LaTeX.


    Reply to this email directly or [1]view it on GitHub.

References

  1. [latex writer] dollar character should not be escaped in LaTeX \url{} links #1913

@jgm jgm closed this as completed in 7050c26 Feb 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants