
이것은 최근 게시물에 대한 후속 조치입니다.추가 공간 없이 제거 가능한 주석 명령 생성. 저는 일반적인 일을 하려고 합니다. 제거 가능한 주석 명령을 만들어서 문서에 기여한 사람들이 서로에게 메모를 남길 수 있도록 하고, 생산 전에 메모가 자동으로 제거될 수 있도록 하려고 합니다. 문제는 여기서 추가 공간을 생성하는 것이 매우 쉽다는 것입니다.
앞서 언급한 게시물의 해결 방법은 다음과 같습니다.
\newif\ifnotes
\makeatletter
\newcommand{\note}[1]{\ifnotes{#1}\else\@bsphack\@esphack\fi}
\makeatother
꽤 잘 작동하지만 완벽하지는 않습니다. 특히 두 개의 음표가 연속으로 발생하는 경우 추가 공간이 추가됩니다. 예를 들어 다음을 고려하십시오.
\notesfalse
Testing \note{X} testing testing.
Testing \note{X}\note{Y} testing testing.
Testing \note{X} \note{Y} testing testing.
\notestrue
Testing \note{X} testing testing.
Testing \note{X}\note{Y} testing testing.
Testing \note{X} \note{Y} testing testing.
위의 결과는 다음과 같습니다.
보시다시피 는 \@bsphack\@esphack
적절하게 제거됩니다.일부여분의 공간을 없애고 메모 하나만 남겨도 아주 잘 작동합니다. 그러나 두 개의 음표가 서로 인접해 있으면 결과에 더 많은 공간이 생성됩니다.
내가 고려한 한 가지 접근 방식은 \note
명령이 다른 음표 옆에 있다는 것을 파악한 다음 추가 \@bsphack\@esphack
. 하지만 과거에 비슷한 명령을 작성하려는 나의 시도는 꽤 형편없었습니다. 이런 일을 겪은 사람이 있습니까? 내 검색어가 비어 있었습니다.
감사해요!
답변1
문제는 \@esphack
레지스터 값을 확인하고 나중에 변경한다는 것입니다 \lastskip
.
따라서 \@esphack
이전 인스턴스의 연속 인스턴스가 작동하는 \note
방식에 영향을 미칩니다 .\@esphack
\note
\@esphack
"뒤로 건너뛰기"가 발생하는 변형이 도움이 될 수 있습니다.
감사합니다
울리히
\documentclass{article}
\newif\ifnotes
\makeatletter
\newcommand{\note}[1]{%
\@bsphack
%=== instead of \@esphack: ===
% \showthe\lastskip
\relax
\ifhmode
\spacefactor\@savsf
\ifdim\@savsk>\z@
\nobreak
\hskip\z@skip
% The previous action will change \lastskip, so:
\hskip-\@savsk
\hskip\@savsk
% now \lastskip is almost \@savsk again.
% \showthe\lastskip
\ignorespaces
\fi
\fi
%===========================
\ifnotes #1\fi
}
\makeatother
\begin{document}
\notesfalse
Testing\note{X}testing testing.
Testing \note{X}testing testing.
Testing\note{X} testing testing.
Testing \note{X} testing testing.
Testing\note{X}\note{Y}testing testing.
Testing\note{X}\note{Y} testing testing.
Testing\note{X} \note{Y}testing testing.
Testing\note{X} \note{Y} testing testing.
Testing \note{X} \note{Y}testing testing.
Testing \note{X} \note{Y} testing testing.
Testing \note{X}\note{Y} testing testing.
Testing \note{X}\note{Y}testing testing.
\notestrue
Testing\note{X}testing testing.
Testing \note{X}testing testing.
Testing\note{X} testing testing.
Testing \note{X} testing testing.
Testing\note{X}\note{Y}testing testing.
Testing\note{X}\note{Y} testing testing.
Testing\note{X} \note{Y}testing testing.
Testing\note{X} \note{Y} testing testing.
Testing \note{X} \note{Y}testing testing.
Testing \note{X} \note{Y} testing testing.
Testing \note{X}\note{Y} testing testing.
Testing \note{X}\note{Y}testing testing.
\end{document}