
일단 설정된 후에 고정되는 카운터를 어떻게 생성합니까?
아이디어는 번호를 매겨야 하는 텍스트에 일종의 설명을 삽입하는 것이지만 소스 코드에 실제 구현 날짜가 증가함에 따라 증가합니다.
소스 코드의 순서에 의존해서는 안 되며, 일부가 제거되더라도 그 값을 유지해야 합니다.
여기에는 MWE가 아니지만 구현이 어떻게 생겼는지에 대한 아이디어가 있습니다.
\documentclass{article}
\begin{document}
\mynote{Some note I've added first},
\mynote{A fourth note},
\mynote{A second note},
\mynote{A fifth note},
\mynote{A third note}.
\end{document}
그러면 다음과 같은 출력이 제공됩니다.
참고 1:내가 먼저 추가한 메모
참고 4:네 번째 메모,
노트 2:두 번째 메모,
참고 5:다섯번째 음표,
노트 3:세 번째 메모.
두 번째 메모가 있는 줄을 삭제하면 다음과 같이 표시됩니다.
참고 1:제가 먼저 추가한 메모가 있습니다.
참고 4:네 번째 메모,
참고 5:다섯번째 음표,
노트 3:세 번째 메모.
답변1
여기에 개념 증명이 있지만 이런 방식으로 보조 파일을 사용하는 것은 매우 위험합니다. 오류로 인해 이전 복사본이 손상되고 메모의 순서가 손실될 수 있기 때문입니다. 따라서 파일을 백업하는 루틴은 .notes
LaTeX 작업이 끝날 때 실행되어야 합니다.
\documentclass{article}
\makeatletter
\newwrite\jjdbout
\newcounter{jjdbnotes}
\def\countnotes#1#2{\stepcounter{jjdbnotes}}
\def\savenote#1#2{%
\expandafter\gdef\csname #1\endcsname{#2}%
\addnote{#1}{#2}%
}
\makeatletter
\def\addnote#1#2{%
\toks@=\expandafter{\jjdbnotes}%
\xdef\jjdbnotes{\the\toks@^^J%
\noexpand\jjdbnote{#1}{#2}}%
}
\makeatother
\let\jjdbnote\countnotes
\InputIfFileExists{\jobname.notes}{}{}
\let\jjdbnote\savenote
\gdef\jjdbnotes{} % initialize
\InputIfFileExists{\jobname.notes}{}{}
\newcommand{\mynote}[1]{%
\par
\ifcsname\pdfmdfivesum{#1}\endcsname
\textbf{Note \csname\pdfmdfivesum{#1}\endcsname: }#1%
\else
\stepcounter{jjdbnotes}%
\expandafter\addnote{\pdfmdfivesum{#1}}{\thejjdbnotes}%
\textbf{Note \thejjdbnotes: }#1%
\fi
}
\AtEndDocument{
\immediate\openout\jjdbout=\jobname.notes
\immediate\write\jjdbout{\unexpanded\expandafter{\jjdbnotes}}
}
\begin{document}
\mynote{Some note I've added first},
\mynote{A fourth note},
\mynote{A second note},
\mynote{A fifth note},
\mynote{A third note}.
\end{document}
파일 .notes
을 두 번 읽습니다. 첫 번째는 항목 수를 세는 것이고 두 번째는 줄에 의미를 할당하는 것입니다.
각 메모는 MD5 체크섬으로 저장되며, 이는 텍스트와 고유하게 연결되어야 합니다. 물론 메모 텍스트가 변경되면 순서가 다시 손실됩니다.
따라서 각 체크섬에는 메모 번호가 할당됩니다. 실행 중에 새 메모를 찾으면 해당 메모가 매크로에 추가되고 해당 내용은 작업이 끝날 때 파일 \jjdbnotes
에 기록됩니다 . .notes
TeX은 기존 파일에 줄을 추가할 수 없습니다.
표시된 출력은 명시된 순서에 따라 행의 주석 처리를 하나씩 제거하여 얻은 것입니다.
더 나은 접근 방식은 메모를 별도의 파일에 저장하여 다음과 같은 notes.tex
형식으로 말하는 것 입니다.
\makeatletter
\newcommand{\savenote}[2]{\@namedef{jjdb@note#2}{#1}}
\newcommand{\mynote}[1]{\@nameuse{jjdb@note#1}}
\makeatother
\savenote{Some note I've added first}{1}
\savenote{A second note}{2}
\savenote{A third note}{3}
\savenote{A fourth note}{4}
\savenote{A fifth note}{5}
그리고 \input{notes}
서문에서 하세요. 그런 다음 문서에서 사용할 수 있습니다
\mynote{1},
\mynote{4},
\mynote{2},
\mynote{5},
\mynote{3}.
이런 방식으로 간단히 메모를 순차적으로 추가하면 됩니다.
답변2
내 생각에 당신이 원하는 것은 바로 LaTeX의 상호 참조가 도움이 되지 않는 경우입니다. 하드 코딩하는 것만으로도 충분합니다. 형식을 지정하려면(굵게 등) description
환경을 사용하거나 다음과 같은 고유한 명령을 만들 수 있습니다.
\newcommand{\mynote}[1]{\par\noindent\bfseries Note#1}
그리고 사용
\mynote{1} some text
\mynote{3} some other text
편집: 다른 사용자가 제안한 대로 '\write command in
\mynote`를 추가하면 다음과 같은 결과를 얻을 수 있습니다.
\documentclass{article}
\begin{document}
\newwrite\notenumber
\immediate\openout\notenumber=note.dat
\newcommand{\mynote}[1]{%
\immediate\write\notenumber{#1}\par\noindent\bfseries Note~#1:}
\mynote{3} the note number 3
\mynote{1} the note number 1
\end{document}
그런 다음 텍스트 편집기나 LaTeX에서 다음 답변을 사용하여 정렬할 수 있습니다.이 질문