나는 내 자신의 숫자 계산과 그 표시를 정의하고 싶습니다.
예를 들어,
오늘 저는 주차장에서 David(P1)를 만났습니다. 데이비드는 친절했어요. 갑자기 나는 그가 내 친구 Susan(P2)이었다는 것을 기억합니다. ...
추가하여 텍스트를 편집하면
오늘 저는 주차장에서 David(P1)를 만났습니다. 데이비드는 친절했어요.David는 John의 아버지입니다(P2).. 갑자기 나는 그가 내 친구 Susan(P3)이라는 것을 기억합니다. ...
숫자가 자동으로 변경될 것으로 예상합니다.
답변1
어쩌면 이런 게 있지 않을까요?
\documentclass{article}
\newcounter{numerations}
\newcommand\nlabel[1]{%
\refstepcounter{numerations}%
\expandafter\xdef\csname REF#1\endcsname{\thenumerations}%
\expandafter\xdef\csname NUMERATIONS\thenumerations\endcsname{#1}%
#1 (P\thenumerations)%
}
\newcommand\nref[1]{#1 (P\csname REF#1\endcsname)}
\newcommand\numeration[1]{\csname NUMERATIONS#1\endcsname{} (P#1)}
\begin{document}
Today I have met \nlabel{David} in the parking. David was friendly.
\textit{David is the father of \nlabel{John}.} Suddenly I remember he was
a friend of mine \nlabel{Susan}...
I can recall the label for \nref{John}, \nref{David}, and or \nref{Susan}.
Or I can invoke them by number: \numeration{2}, \numeration{1}, and or
\numeration{3}.
\end{document}
답변2
\nameref
다음은 사람의 이름을 참조하는 선택적 인수를 사용하여 작업(필요한 경우) 및 자동 라벨링 기능을 갖춘 버전입니다 . 반면 추가 \label
명령은~ 후에매크로 \newpersons
는 개인의 번호(예: P1 등)를 참조합니다.
\documentclass{article}
\usepackage{xparse}
\newcounter{person}
\renewcommand{\theperson}{P\arabic{person}}
\makeatletter
\NewDocumentCommand{\newperson}{O{#2}m}{%
\protected@edef\@currentlabel{#1}%
% If hyperref is not loaded, \protected@edef\currentlabelname does no harm here
\protected@edef\@currentlabelname{#1}% for nameref.
\label{#2}%
\refstepcounter{person}%
#1~(\theperson)%
}
\makeatother
\usepackage{hyperref}
\begin{document}
Today I have met \newperson{David} in the parking. David was friendly.
\textit{\ref{David} is the father of \ref{John}.} Suddenly I remember he was
a friend of mine \newperson{Susan}\label{susansnumber}...
I can recall the label for \newperson{John}, \ref{David}, and or \nameref{Susan} or call them by a reference to the number with \ref{susansnumber}.
\end{document}
답변3
다음 예에서는 \newperson{<name>}
이름과 그 뒤에 증가된 카운터 형식을 설정하는 방법을 제공합니다 (P<num>)
.
\documentclass{article}
\newcounter{person}
\newcommand{\newperson}[1]{%
\refstepcounter{person}%
#1~(P\theperson)}
\begin{document}
Today I have met David~(P1) in the parking. David was friendly.
David is the father of John~(P2). Suddenly I remember he was a friend of mine, Susan~(P3).
Today I have met \newperson{David} in the parking. David was friendly.
David is the father of \newperson{John}. Suddenly I remember he was a friend of mine, \newperson{Susan}.
\end{document}
일관성을 위해 이미 이름이 지정된(신규 아님) 사람을 참조할 수 있도록 \label
- 시스템 을 사용하도록 확장할 수 있습니다 . 다음은 를 사용하여 참조할 수 있는 \ref
구현입니다 . no가 제공 되면 다음이 사용됩니다.\newperson[<tag>]{<name>}
\refperson{<tag>}
<tag>
<name>
\documentclass{article}
\newcounter{person}
\makeatletter
\newcommand{\newperson}[2][]{%
\refstepcounter{person}% New person added
\def\@currentlabel{#2}% Update label
\@currentlabel~(P\theperson)% Set person
% https://tex.stackexchange.com/a/53091/5764
\if\relax\detokenize{#1}\relax
\label{#2}%
\else
\label{#1}%
\fi
}
\makeatother
\newcommand{\refperson}[1]{\ref{#1}}%
\begin{document}
Today I have met Davidofilofsky~(P1) in the parking. Davidofilofsky was friendly.
Davidofilofsky is the father of John~(P2). Suddenly I remember he was a friend of mine, Susan~(P3).
Today I have met \newperson[david]{Davidofilofsky} in the parking. \refperson{david} was friendly.
\refperson{david} is the father of \newperson{John}. Suddenly I remember he was a friend of mine, \newperson{Susan}.
\end{document}