# Is there a chance to get SyncTeX work with text within environments?

I know that SyncTeX does not work correctly in Beamer (see Inverse PDF Search in beamer).

But there seems to be also a problem with inverse search in environments defined with \NewEnviron.

I want to call something like this:

\begin{foo}{x}{y}
bla bla
\end{foo}


It does not need to be an environment. But I do not know what to use else because I want to control the body which is possible with \BODY in \NewEnviron but not possible with \newenvironment.

So is it possible to define an environment-like thing, where SyncTeX points to the text in the environment and not at the end of the environment?

In itemize-environments it seems to work. Does someone know how it is implemented there?

Example:

\documentclass{letter}
\usepackage{environ}

\newif\ifshow

\NewEnviron{foo}[3]{
\ifshow
#1\\
\BODY
-----------
\else
\fi
}

\begin{document}
\begin{foo}{hide}{1}{2}
hidden Text
\end{foo}

\showtrue

\begin{foo}{show}{2}{1}
\begin{itemize}
\item a
\item b
\item c
\end{itemize}
\end{foo}

\begin{itemize}
\item d
\item e
\item f
\end{itemize}

\end{document}


For a, b, c inverse search does not work for d, e, f it works. For me it is important that the original text body can be replaced.

• The problem is that \NewEnviron grabs the entire environment body and processes it only at the end, so SyncTeX cannot know from where within the environment each specific piece of text came from. As far as SyncTeX knows it was all stored in the \end{foo}. I'm afraid the answer is: not possible Nov 19, 2020 at 18:28
• I know that \NewEnviron does not work. Therefore, asked for an alternative. It should be possible if itemize works. Nov 19, 2020 at 18:50
• That depends on what your environment does. Without seeing the definition it's impossible to say. Can you make a compilable example, please? Nov 19, 2020 at 18:58
• I added an example. Nov 20, 2020 at 7:49

We can realize it with \newenvironment and \comment from verbatim:

\documentclass{letter}
\usepackage{verbatim}

\newif\ifshow

\newenvironment{foo}[3]{
\ifshow
#1\\
\else
\def\a{#1}
\def\b{#2}
\def\c{#3}
\expandafter\comment
\fi
}
{
\ifshow
-----------
\else
\expandafter\endcomment
\fi
}

\begin{document}
\begin{foo}{hide}{1}{2}
hidden Text
\end{foo}

\showtrue

\begin{foo}{show}{2}{1}
\begin{itemize}
\item a
\item b
\item c
\end{itemize}
\end{foo}

\begin{itemize}
\item d
\item e
\item f
\end{itemize}

\end{document}


Then inverse search does also work for a, b and c.