texstudio-org / texstudio

TeXstudio is a fully featured LaTeX editor. Our goal is to make writing LaTeX documents as easy and comfortable as possible.
http://www.texstudio.org/
GNU General Public License v3.0
2.79k stars 343 forks source link

"Go to Source" functionality does not work with the comment package's \includecomment #1959

Open JAEarly opened 2 years ago

JAEarly commented 2 years ago

I use the comment package to selectively remove parts of work (e.g., long appendices) to produce smaller documents or save compile time. This is enabled through the \includecomment{<partname>} and \excludecomment{<partname>} functions, which either include or exclude the content enclosed between \begin{<partname>} and \exclude{<partname>}. When using \includecomment{<partname>}, the "Go to Source" function is broken, as it does not move the cursor in the editor.

Environment

Expected behavior

When using "Go to Source" on content that is enclosed between \begin{<partname>} and \exclude{<partname>} while using \includecomment{<partname>} should work as normal, i.e., the editor should jump to the relevant part of the Latex source.

Actual behavior

The cursor in the editor does not move at all for any content enclosed between \begin{<partname>} and \exclude{<partname>}. It works fine for any content outside of that area (i.e., it works as normal), just not for content in that area, even though the content is rendered exactly as it would be normally.

How to reproduce

Below is a minimal reproducible example. "Go to Source" works fine for page one, but does not work at all for page two or three.

\documentclass[]{article}

\usepackage{lipsum}  
\usepackage{comment}

% Toggle pages two and three on/off with \includecomment and \excludecomment
\includecomment{excludedpart}

\begin{document}

\lipsum[1]

\clearpage

\begin{excludedpart}
\lipsum[2]
\clearpage
\lipsum[3]
\end{excludedpart}

\end{document}
muzimuzhi commented 2 years ago

Seems to be a synctex limitation. Tests show an input file will be recorded by synctex only if its file extension is in a specific list. For example, \input{temp.tmp} is not recorded, but \input{temp.tex} is. Here the "recoded by synctex" means you can find a line Input:<num>:<full path> at the beginning of unzipped .synctex.gz file.

Relation to comment package: with \includecomment{excludedpart} every excludedpart env will first write its content to file comment.cut, then input it back. Since file extension cut is ignored by synctex and the contents of comment.cut might be overwritten by following excludedpart usages, inverse searching won't work for the output of \includecomment environments.

muzimuzhi commented 2 years ago

Tests show an input file will be recorded by synctex only if its file extension is in a specific list. For example, \input{temp.tmp} is not recorded, but \input{temp.tex} is.

I was wrong. Every input file is recorded.

Using a simplified example

\documentclass[]{article}
\begin{document}
text
\clearpage
\input{temp.tmp}
\end{document}

where temp.tmp contains

% this is `temp.tmp`
second page \newpage
third page

texstudio fails to do inverse searching on the second and third pages, while overleaf works well.