Synctex: 콘텐츠에 액세스하는 환경에서 작동하도록 만듭니다(예: Environ 또는 xparse +b 옵션).

Synctex: 콘텐츠에 액세스하는 환경에서 작동하도록 만듭니다(예: Environ 또는 xparse +b 옵션).

environand \BODY또는 xparseand 를 사용하여 환경을 생성하면 +bsynctex 기능이 중단됩니다. 적절한 줄로 이동하는 대신 환경의 끝으로 이동합니다. 매크로에 넣는 내용이 \BODYLaTeX에 방해가 되는 것 같은데 어떻게든 해결할 수 있을지 궁금합니다(결국 lualatex에서)

MWE

\documentclass[]{article}
\usepackage{environ}% http://ctan.org/pkg/environ

%% The +b is needed because in real life the text may be moved to another file
\NewDocumentEnvironment{testSynctex}{s+b}{
  \IfBooleanTF{#1}{}{#2}%
}{}

\NewEnviron{testSynctexEnviron}{%
  \BODY
}

\begin{document}

\section{xparse}

\begin{testSynctex}
  This

  is

  a

  long

  text

  try

  to synctex

  me !
\end{testSynctex}

\section{xparse*}

\begin{testSynctex}*
  This

  text
  should

  be

  hidden
\end{testSynctex}

\section{environ}

\begin{testSynctexEnviron}
  This

  is

  a

  long

  text

  try

  to synctex

  me !
\end{testSynctexEnviron}

\end{document}

편집하다

user202729가 제안한 솔루션은 위의 MWE에 대해 훌륭하게 작동합니다(그리고 확실히 내 질문의 일부에 대한 답변이며 더 일반화 가능한 답변을 찾을 수 없는 경우 확실히 유용할 것입니다). 그러나 user202729가 제안한 솔루션이 더 이상 작동하지 않는 경우 해결하고 싶은 또 다른 MWE가 있습니다.

두 섹션 사이에 텍스트를 복제하고 있습니다(해당 파일을 입력하기 전에 먼저 파일에 내용을 작성하여). 불행하게도 이로 인해 synctex가 중단됩니다. 복사된 텍스트(메인 파일 대신 더미 파일로 이동)뿐만 아니라 초기 텍스트(환경의 끝으로 이동)에도 적용됩니다.

최소한 첫 번째 섹션의 텍스트에 대해 synctex를 작동시키는 것이 가능합니까? 그리고 두 번째 섹션의 텍스트에도 작동하도록 만들 수 있다면... 정말 멋질 것입니다.

MWE:

\documentclass{article}
\def\nameOfFile{mydummyfile.tex}

%% Write to a file
\newwrite\appendwrite
\NewDocumentCommand\writetofile{m+m}{%
  %% Open the file
  \immediate\openout\appendwrite #1\relax%
  %% Write the text to the file
  \immediate\write\appendwrite{#2}%
  %% Close the file
  \immediate\closeout\appendwrite%
}
  
\NewDocumentEnvironment{duplicateContentKeepSynctex}{+b}{%
  #1%
  \writetofile{\nameOfFile}{#1}%
}{}

\begin{document}

\section{Main body}

\begin{duplicateContentKeepSynctex}
  This content is duplicated to another section.

  However synctex does not work in both sections.

  Ideally I'd love to make synctex work in both sections (in such a way that it always links to the main file, NOT mydummyfile).

  But I guess it's impossible.

  But at least, is it possible to make it work for the first section?
\end{duplicateContentKeepSynctex}

\section{Duplicated section}

\input{\nameOfFile}

\end{document}

답변1

매크로 확장 언어에서 이것이 어떻게 가능한지 모르겠습니다. 매크로의 내용은 처리되지 않으므로 매크로가 사용되는 오류 메시지나 synctex 마커만 얻을 수 있으며 정의 근처에는 없을 수도 있습니다. 이러한 경우 환경 본문을 저장하는 내부 매크로는 정의에 가깝게 사용되므로 synctex 데이터는 소스에 가깝지만 tex에서는 예제가 다음과 같습니다.

\def\abc{
some text

XXX

that gets saved here
}

multiple pages of arbitrary document source

\abc

\abc그리고 당신은 synctex가 "여러 페이지 나중에" 라는 줄이 아닌 정의 중간에 XXX를 줄 4와 연결하도록 요청하고 있습니다 \abc.

답변2

좋습니다. 해결책입니다.

lualatex로 컴파일하면 두 섹션 모두 synctex가 유지되고, 그렇지 않으면 첫 번째 섹션만 유지됩니다.

%! TEX program = pdflatex

\documentclass{article}
\usepackage{saveenv}
\usepackage{currfile}
\usepackage{rescansync}

  
\ExplSyntaxOn
\NewDocumentEnvironment{duplicateContentKeepSynctex}{}{%
  \rescansyncSaveenvghostPacked \savedcontent
}{
  \endrescansyncSaveenvghostPacked
}
\ExplSyntaxOff

\begin{document}

\section{Main body}

\begin{duplicateContentKeepSynctex}
  This content is duplicated to another section.

  However synctex does not work in both sections.

  Ideally I'd love to make synctex work in both sections (in such a way that it always links to the main file, NOT mydummyfile).

  But I guess it's impossible.

  But at least, is it possible to make it work for the first section?
\end{duplicateContentKeepSynctex}

\section{Duplicated section}

\rescansyncPacked \savedcontent

\end{document}

실제로 콘텐츠를 파일에 기록하는 것이 아니며, 콘텐츠는 \savedcontent사용자가 건드릴 수 없는 특정 형식으로 저장됩니다. 사용자가 컨텐츠를 수동으로 조작하려면 rescansync패키지의 프로그래밍 API를 사용하십시오.

메모

관련 정보