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

[bug] texlab considers links containing % in \href as a comment #1279

Closed
marcfranquesa opened this issue Nov 25, 2024 · 7 comments · Fixed by #1291
Closed

[bug] texlab considers links containing % in \href as a comment #1279

marcfranquesa opened this issue Nov 25, 2024 · 7 comments · Fixed by #1291

Comments

@marcfranquesa
Copy link

marcfranquesa commented Nov 25, 2024

Links to files containing spaces contain %, and \href allows you to insert the link as is. texlab seems to understand it as a comment and considers the { from \href to not be closed, therefore giving an error expecting a }.

Reproducible example:

\documentclass[12pt]{article}

\usepackage{hyperref}

\begin{document}

\href{https://github.com/latex-lsp/texlab/example%20file.pdf}{URL with \%}.

\end{document}

Thanks!

@nolanking90
Copy link
Contributor

You can escape the % as \%,

\href{https://github.com/latex-lsp/texlab/example\%20file.pdf}{URL with \%}.

Alternatively, you can use a space instead of %20,

\href{https://github.com/latex-lsp/texlab/example file.pdf}{URL with \%}.

Both of these produce the desired result without the diagnostic.

The hyperref documentation says:

The special characters # and % do not need to be escaped in any way (unless
the command is used in the argument of another command).

I read this to mean that hyperref does not care if you escape the % or not.

@marcfranquesa
Copy link
Author

Alright, thanks. I assume there is no intention to support having these characters as is (without escaping them) then?

@nolanking90
Copy link
Contributor

I’m open to working on it if you have a suggestion for how to do it. I thought about it for a bit and it’s not obvious to me how to do it without some complicated look ahead while walking the tree. @pfoerster thoughts?

@marcfranquesa
Copy link
Author

Great, thanks a lot! I am very new to LSPs, I'll let you know if I come up with something.

@pfoerster
Copy link
Member

I’m open to working on it if you have a suggestion for how to do it. I thought about it for a bit and it’s not obvious to me how to do it without some complicated look ahead while walking the tree. @pfoerster thoughts?

I think you need to do this at the parser/lexer level and introduce a PATH token. Walking the tree would be difficult because you have to split and tokenize the COMMENT token again.

@nolanking90
Copy link
Contributor

I think I have this working now, and I've added one unit test for this command:

\href{https://www.test.com/url%20%with%20space}{A test URL}

I could use suggestions for other test cases to check before I push a PR.

@marcfranquesa
Copy link
Author

also maybe adding support for \url{}?

and, not sure how much of use it would be, but what about a unit test such as,

% \href{https://www.test.com/url%20%with%20space}{A test URL}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants