모든 숫자 뒤에 있는 세 객체
LaTeX 카운터는 매크로가 아닙니다. \newcounter{foo}는 \c@foo라는 이름의 정수 레지스터를 만들고(그래서 \value{foo}, 문자 그대로 \csname c@foo\endcsname인 그것, 은 TeX \count입니다), 서로 다른 질문에 답하는 네 개의 동반 매크로도 함께 만듭니다. \thefoo는 인쇄되는 표현, 제목이나 환경이 보여주는 것이지요. \p@foo는 참조 접두사로, \label이 값을 .aux에 쓸 때만 \thefoo 앞으로 접착됩니다. \theHfoo는 hyperref가 PDF 닻의 이름을 짓는 데 쓰는 목적지 표현이고, \cl@foo는 초기화 목록입니다: foo가 밟힐 때마다 0으로 돌아가는 카운터들이죠.
첫 둘을 혼동하는 것이 "번호가 이상한데 이유를 모르겠다"는 보고의 대부분입니다. \thefoo를 다시 정의하면 페이지와 참조가 함께 바뀌고, \p@foo를 다시 정의하면 \ref가 말하는 것만 바뀌며, \theHfoo를 다시 정의하면 독자가 보는 것은 하나도 바뀌고 PDF 뷰어가 하는 일만 전부 바뀝니다.
표현 자체가 다시 정의할 수 있는 매크로입니다. \arabic, \roman, \Roman, \alph, \Asbuk, \asbuk(마지막 둘은 키릴용, babel이 제공)이 표준이고, 기호 열용 \fnsymbol이 더 있죠. 어느 것이든 리터럴 텍스트와 결합할 수 있어 \renewcommand{\theexercise}{(\alph{exercise})}는 합법이고, \thepage, \thechapter, \thesection도 다른 카운터와 같은 평범한 카운터입니다.
문서를 조용히 망가뜨리기 때문에 외워 둘 제약이 하나 있습니다. 커널은 \thefoo와 \p@foo가 \edef\bar{\thefoo}가 그 순간의 값을 잡도록 정의되어야 한다고 적어 둡니다. \arabic{}과 친구들이 보장하는 것이 바로 그것이고, 늦게 전개되는 매크로로 쌓은 정의는 보장하지 못하죠 — 그래서 카운터를 다시 정의하는 패키지 위에 얹은 \thefoo는 현재 값이 아니라 문서의 마지막 값을 찍을 수 있습니다.
n_{\text{print}} = (n_{\text{parent}},\ n_{\text{raw}}) \qquad (2,4) \mapsto 2.4
세 줄의 계약: newcounter, setcounter, usecounter
첫 줄 — \newcounter{foo}[parent]. 레지스터를 선언하고, 선택 인자를 주면 내부 명령 \@addtoreset로 부모의 초기화 목록에 foo를 더합니다. 선택 인자가 하는 일은 오직 그것입니다. \thefoo는 건드리지 않아요. \newcounter{exercise}[section] 다음에도 번호는 2.4가 아니라 여전히 4로 찍힙니다. 선택 인자가 그런 명성을 가진 이유는 표준 클래스가 인쇄 부분을 손으로 처리하기 때문인데, article.cls에는 \newcounter{subsection}[section] 뒤에 \renewcommand\thesubsection{\thesection.\arabic{subsection}}이 이어져 있고, 두 줄이 하나로 읽히죠.
둘째 줄 — \setcounter{foo}{<value>}. 설정과 그 형제 \addtocounter는 전역입니다(커널이 \global로 감싸 두죠). 그래서 그룹 안에서 바꾼 카운터는 나중에 새 값을 유지하는데, 평범한 매크로와 다른 점입니다. 둘째 인자는 정수 표현식이고, 그래서 \setcounter{chapter}{\value{chapter}+1}과 \addtocounter{page}{-2}가 모두 합법이며, 표현식이 예상되는 자리에 \stepcounter를 쓰거나 중괄호 안에 뜬 공백을 두면 안 되는 것이죠. 인자는 수로 읽히고, 해석하지 못하는 토큰은 표현식을 조용히 끝냅니다.
셋째 줄 — \usecounter{foo}. 이것은 list 환경의 카운터 인터페이스이고, enumerate가 위에서 지어진 토대입니다. 설정 인자 안에 쓴 \begin{list}{\label}{\usecounter{enumi}}은 \item이 foo를 밟고 목록 안의 \label이 그 카운터를 가리키도록 선언하죠. 그 뒤에 있는 커널 소스 한 줄은 \def\usecounter#1{\@nmbrlisttrue\def\@listctr{#1}\setcounter{#1}\z@}이고 — 마지막 부분에 주목하세요, \usecounter는 카운터를 0으로 만듭니다. 그래서 목록 앞에 둔 \setcounter{exercise}{6}은 잊혀져요. 일곱에서 시작하는 올바른 방법은 \usecounter 다음에 같은 설정 인자 안에서 \setcounter를 쓰는 것입니다.
v = 4 \;\Longrightarrow\; \mathrm{iv},\ \mathrm{d},\ \mathrm{IV},\ 4
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[a4paper,margin=2.5cm]{geometry}
% ---- 1. the counter exists, and it resets with its parent.
% Note: this is ONLY the reset. \newcounter does not touch the printed form.
\newcounter{exercise}[section]
% ---- 2. how the number is printed on the page.
\renewcommand{\theexercise}{\thesection.\arabic{exercise}}
% ---- 3. a solution counter whose heading is short but whose \ref is full:
% \p@<counter> is prefixed to \the<counter> only when \label is written.
\newcounter{solution}
\renewcommand{\thesolution}{\arabic{solution}}
\makeatletter
\renewcommand{\p@solution}{Solution \thesection.} % \ref -> "Solution 1.3"
\makeatother
\newenvironment{solution}
{\par\smallskip\noindent\refstepcounter{solution}%
\textbf{Solution \thesolution.}\ }
{\par\medskip}
% ---- a hand-built numbered environment: three lines of machinery
\newenvironment{exercise}
{\par\medskip\noindent
\refstepcounter{exercise}% <- makes \label work
\textbf{Exercise \theexercise.}\itshape\space}
{\par\medskip}
\begin{document}
\section{First-order equations}\label{sec:one}
\begin{exercise}
Solve $x^{2} + 2bx + c = 0$ and verify the roots. \label{ex:quad}
\end{exercise}
Reference to \textbf{\ref{ex:quad}} works only because the environment called
\verb|\refstepcounter|, not \verb|\stepcounter|.
\begin{solution}
Complete the square: $(x+b)^{2} = b^{2} - c$. \label{sol:quad}
\end{solution}
The heading reads \thesolution{} while \verb|\ref{sol:quad}| reads
\ref{sol:quad}, because \verb|\p@solution| adds the prefix that only the
reference sees.
\subsection{A list that reuses a counter}
A \texttt{list} environment counts with any counter you hand it, through
\verb|\usecounter| --- which \emph{resets that counter to zero} when the list
begins, so a preceding \verb|\setcounter| has to be repeated inside the setup:
\begin{list}{\textbf{\theexercise.}}{\usecounter{exercise}\setcounter{exercise}{6}%
\setlength{\leftmargin}{3.2em}\setlength{\labelwidth}{2.6em}}
\item continues from 7, because \verb|\item| steps the list counter.
\item and 8 here.
\end{list}
\section{Second section}
\begin{exercise}
The counter restarted: this is \ref{ex:quad} again? No ---
this new exercise is \arabic{exercise} in section \thesection.
\end{exercise}
\subsection*{Skipping and setting}
\setcounter{exercise}{10}
Now manually at \theexercise.
\addtocounter{exercise}{-3}
And after a negative step, \theexercise.
\end{document}
stepcounter 대 refstepcounter
\stepcounter{foo}는 두 일을 합니다: 레지스터를 올리고 foo의 초기화 목록에 있는 모든 카운터를 되돌리죠. \refstepcounter{foo}는 그 둘에 하나를 더하고, 그 하나가 동작하는 환경과 장식만 하는 환경의 차이입니다. \@currentlabel을 저장하는데 — 그 순간 전개된 문자열 \p@foo\thefoo — 함께 \@currentHref와 \@currentcounter, 즉 목적지 이름과 카운터의 정체도 기록합니다.
\label{name}이 \@currentlabel을 .aux에 쓰기 때문에, 맨 \stepcounter로 움직인 카운터는 참조될 수 없어요. 그 뒤의 \label은 이전 \refstepcounter이 남긴 것을 기록하므로 \ref{ex:one}은 섹션 번호나 앞의 exercise나 ??를 찍습니다. 표준 정리 유사 환경들이 \refstepcounter를 쓰는 정확한 이유이고, 상호 참조 강의의 "라벨은 카운터 뒤에" 규칙 뒤에 기계가 있다는 근거이기도 하죠.
수는 진행하되 참조 가능해지길 원하지 않을 때 \stepcounter를 의도적으로 쓰세요: 푸터에 쓰는 누적 값, 루프 카운터, 또는 여백을 위해 카운터를 공유하는 번호 없는 환경이 그렇습니다. 이 구별은 \item의 동작도 설명하는데, 리스트 기계가 \refstepcounter\@listctr을 부르는 자리가 바로 그곳이죠. 그래서 enumerate 안의 \label은 enumi를 받아들이지만, itemize 안의 \label은 아무것도 얻지 못합니다 — itemize는 결코 \@nmbrlisttrue를 켜지 않으니까요.
초기화 위계와 카운터의 부모 다시 정하기
초기화 관계는 \cl@<parent>라는 이름의 목록에 살고, 부모를 밟는 것은 그 목록을 훑는 일입니다. 커널은 익숙한 위계를 그렇게 배열했어요 — footnote? 아닙니다: equation, figure, table과 각 구분 수준은 section과 함께 초기화되고, section은 subsection의 부모와 함께, book 계열 클래스에서 chapter까지 그렇게 올라갑니다. 내부 명령 \@addtoreset{child}{parent}로 목록에 더하고, \@removefromreset{child}{parent}로 빼고, 2018 릴리스 이래 커널의 사용자 수준 쌍 \counterwithin{child}{parent}와 \counterwithout{child}{parent}를 쓰면 되죠. 구설치에서는 chngcntr 패키지가 제공합니다.
둘은 이름 이상으로 다르고, 그 차이가 사람들이 걸리는 지점입니다. \counterwithin은 일의 두 절반을 모두 해요 — 초기화를 더하고 \thechild를 \theparent.arabic(child)로 다시 정의하죠 — 반면 \newcounter{child}[parent]는 초기화만 합니다. 그래서 \newcounter{exercise}[chapter]를 \newcounter{exercise}에 \counterwithin{exercise}{chapter}을 더하는 형태로 바꾸는 것은 장식용 리팩토링이 아니에요. 두 부분 번호까지 함께 주는 버전이니까요.
세 번째 관계도 있습니다, 중첩이 아니라 공유: 하나의 열로 함께 세는 두 환경. amsthm은 \newtheorem{lemma}[theorem]{Lemma}로 이것을 표현하고, 날것 카운터에서는 둘을 같은 레지스터에 두고 다른 단어를 찍는 것이 동치인데, 최신 릴리스 이래 커널은 카운터 별명을 통해 그것을 지원합니다. 실무적으로는 하나의 카운터를 쓰되 제목 매크로를 다르게 쓰거나, 두 열이 독립적으로 돈 사실을 인정하고 본문에 그렇게 쓰세요.
초기화에 관한 마지막 미묘함: 초기화는 부모가 밟힐 때 일어나고 설정될 때 일어나지 않습니다. \setcounter{section}{3}은 cl@section의 카운터들을 초기화하지 않아요. 그래서 손으로 섹션을 건너뛰는 문서는 낡은 수식 번호를 유지하고, 다중 저자 문서에서 손으로 쓴 \setcounter{chapter}{...}가 5장에 "Theorem 4.7"을 만들어 내는 것도 그 이유 중 하나입니다.
c_{\text{child}} \leftarrow 0 \quad \text{whenever} \quad c_{\text{parent}} \leftarrow c_{\text{parent}} + 1
번호 매기는 환경을 직접 만들기
번호 매기는 환경은 네 줄이고, 한 번 써 보면 amsthm의 신비는 증발합니다: \newenvironment{exercise}{\par\medskip\noindent\refstepcounter{exercise}\textbf{Exercise \theexercise.}\ }{\par\medskip}. \refstepcounter가 참조 기계이고, \theexercise가 눈에 보이는 번호이며, 두 \par는 환경이 주변 문단을 삼키는 것을 막아 주죠. 연속된 exercise들이 하나의 틈을 공유하게 하려면 \medskip 대신 \addvspace{\medskipamount}를 쓰면 됩니다.
실제 문서에서 중요한 다듬기 두 가지. exercise에 선택 제목을 주려면 인자와 함께 선언하세요 — \newenvironment{exercise}[1]{...\textbf{Exercise \theexercise.\ifblank{#1}{}{ (#1)}}...}{...} — etoolbox의 \ifblank를 쓰든 커널의 \ifstrempty를 쓰든, 그리고 \nameCref와 PDF 북마크가 제목을 싣게 하려면 그 제목을 \@currentlabelname에 넣으면 됩니다. 환경을 끊기게 하거나 끊기지 않게 하려면 도구는 카운터 변경이 아니라 \needspace{3\baselineskip} 또는 minipage 감싸기입니다.
이것을 문서가 아니라 클래스나 패키지 안에서 쓴다면, @ 문자가 카테고리 코드로 보호된다는 점을 기억하세요. 정의를 \makeatletter ... \makeatother로 감싸고, 환경이 내부 상태를 써야 한다면 \exercise를 손으로 다시 정의하는 것보다 현대 커널이 제공하는 훅 인터페이스(\AddToHook)를 선호하세요.
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[a4paper,margin=2.5cm]{geometry}
% ---- 1. the counter exists, and it resets with its parent.
% Note: this is ONLY the reset. \newcounter does not touch the printed form.
\newcounter{exercise}[section]
% ---- 2. how the number is printed on the page.
\renewcommand{\theexercise}{\thesection.\arabic{exercise}}
% ---- 3. a solution counter whose heading is short but whose \ref is full:
% \p@<counter> is prefixed to \the<counter> only when \label is written.
\newcounter{solution}
\renewcommand{\thesolution}{\arabic{solution}}
\makeatletter
\renewcommand{\p@solution}{Solution \thesection.} % \ref -> "Solution 1.3"
\makeatother
\newenvironment{solution}
{\par\smallskip\noindent\refstepcounter{solution}%
\textbf{Solution \thesolution.}\ }
{\par\medskip}
% ---- a hand-built numbered environment: three lines of machinery
\newenvironment{exercise}
{\par\medskip\noindent
\refstepcounter{exercise}% <- makes \label work
\textbf{Exercise \theexercise.}\itshape\space}
{\par\medskip}
\begin{document}
\section{First-order equations}\label{sec:one}
\begin{exercise}
Solve $x^{2} + 2bx + c = 0$ and verify the roots. \label{ex:quad}
\end{exercise}
Reference to \textbf{\ref{ex:quad}} works only because the environment called
\verb|\refstepcounter|, not \verb|\stepcounter|.
\begin{solution}
Complete the square: $(x+b)^{2} = b^{2} - c$. \label{sol:quad}
\end{solution}
The heading reads \thesolution{} while \verb|\ref{sol:quad}| reads
\ref{sol:quad}, because \verb|\p@solution| adds the prefix that only the
reference sees.
\subsection{A list that reuses a counter}
A \texttt{list} environment counts with any counter you hand it, through
\verb|\usecounter| --- which \emph{resets that counter to zero} when the list
begins, so a preceding \verb|\setcounter| has to be repeated inside the setup:
\begin{list}{\textbf{\theexercise.}}{\usecounter{exercise}\setcounter{exercise}{6}%
\setlength{\leftmargin}{3.2em}\setlength{\labelwidth}{2.6em}}
\item continues from 7, because \verb|\item| steps the list counter.
\item and 8 here.
\end{list}
\section{Second section}
\begin{exercise}
The counter restarted: this is \ref{ex:quad} again? No ---
this new exercise is \arabic{exercise} in section \thesection.
\end{exercise}
\subsection*{Skipping and setting}
\setcounter{exercise}{10}
Now manually at \theexercise.
\addtocounter{exercise}{-3}
And after a negative step, \theexercise.
\end{document}
새 카운터를 hyperref와 cleveref에게 알리기
새 카운터는 추가 매크로 셋이 존재할 때까지 참조 기계에 보이지 않습니다. hyperref의 \autoref는 \<counter>autorefname을 읽으므로 \newcommand*{\exerciseautorefname}{Exercise}를 써야 해요. 없으면 \autoref{ex:one}는 명사 없이 번호만 찍습니다. hyperref의 목적지 이름은 \theHexercise을 읽는데, 커널이 2024 릴리스 이래 모든 카운터에 대해 미리 만들어 둡니다(\@definecounter가 \theH<name>를 \number\value{<name>}으로 정의하죠). 맨 정수는 한 부모 안에서만 유일하므로 report에서는 \thechapter.\arabic{exercise}로 만들어야 하고, 아니면 로그가 중복 목적지 경고로 채워집니다.
cleveref는 자기 표를 두 개 유지합니다: 소문수 단수·복수용 \crefname{exercise}{exercise}{exercises}와 대문수 쌍용 \Crefname{exercise}{Exercise}{Exercises}이 그것이죠. 두 번째 환경이 첫 번째의 어휘를 재사용해야 한다면 \crefalias{subexercise}{exercise}가 문자열을 복제하지 않고 그렇게 선언합니다. 그리고 형식이 필요해서 — 괄호로 싼 번호, 수학 모드 안의 접두사 — 그렇다면 \crefformat{exercise}{\textbf{#2#1#3}}가 cleveref가 채워 넣는 세 슬롯(열기, 번호, 닫기)을 줍니다.
\p@ 접두사는 여기서 제 값을 합니다. 참조 문자열이 만들어질 때만 적용되므로, 제목은 짧은 것을 찍고 \ref은 완전한 것을 찍게 할 수 있어요. \renewcommand{\thesolution}{\arabic{solution}}에 \renewcommand{\p@solution}{\thesection.}을 더하면 제목은 "Solution 3"으로 읽히고cross-reference는 "Solution 2.3"으로 읽힙니다. 대칭적인 재주는 \p@solution에 명사를 넣는 것이고, 그렇게 하면 \ref은 스스로 설명하지만 \autoref까지 쓰면 명사가 두 번 찍히는 대가가 있으니, 명사를 소유할 층 하나를 정해 거기에 머무세요.
\underbrace{3}_{\text{printed by the heading}} \ne \underbrace{\text{Solution }2.3}_{\text{stored for the reference}}
\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=2.5cm]{geometry}
\newcounter{exercise}[chapter]
\renewcommand{\theexercise}{\thechapter.\arabic{exercise}}
\newenvironment{exercise}
{\par\medskip\noindent
\refstepcounter{exercise}%
\textbf{Exercise \theexercise.}\ }
{\par\medskip}
% --- the machinery that has to be told about a new counter -------------
\makeatletter
% hyperref: \autoref builds its word from \<counter>autorefname
\newcommand*{\exerciseautorefname}{Exercise}
% hyperref: the destination name must be unique across the document
\renewcommand{\theHexercise}{\thechapter.\arabic{exercise}}
\makeatother
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue}
\usepackage[capitalise]{cleveref}
% cleveref keeps its own tables: singular/plural, lower and upper case
\crefname{exercise}{exercise}{exercises}
\Crefname{exercise}{Exercise}{Exercises}
\begin{document}
\chapter{Linear algebra}
\section{Systems}\label{sec:sys}
\begin{exercise}\label{ex:one}
Solve $Ax = b$ for $A$ invertible.
\end{exercise}
\begin{exercise}\label{ex:two}
Solve the same system by row reduction.
\end{exercise}
All four reference styles at once: \ref{ex:one}, \theexercise,
\autoref{ex:two}, \cref{ex:one,ex:two}, \Cref{ex:two},
and \cpageref{ex:one}.
\subsection*{Re-parenting a counter}
\begin{verbatim}
\counterwithin{exercise}{section} % 2.3: reset with section, prefix included
\counterwithout{exercise}{section} % 7 : independent numbering again
\end{verbatim}
Both are kernel commands since the 2018 release; on an older installation the
package \texttt{chngcntr} provides them. \verb|\newcounter{exercise}[chapter]|
by contrast only ever does the reset half of that job.
\end{document}
페이지 번호도 카운터입니다
\thepage는 기본 클래스에서 \arabic{page}이고, 다른 카운터처럼 다루는 것을 막는 장치는 없습니다. 단 위험한 차이가 하나 있어요: page는 출력 루틴이 밟으므로 \setcounter{page}는 비동기입니다. 7페이지에서 설정한다고 1에서 6페이지까지 소급해 다시 번호가 매겨지지 않고, 상자나 마크 안에서 설정하면 의도하지 않은 어딘가에 착륙하죠.
지원되는 인터페이스는 \pagenumbering{<style>}이고, 두 일을 합니다: \thepage를 바꾸고 카운터를 1로 초기화하죠. 그래서 \mainmatter의 \pagenumbering{arabic}이 세기를 다시 시작하고, \pagenumbering을 쓰는 대신 \setcounter{page}{1}을 적는 것은 득보다 실이 큰 지름길입니다. hyperref와 페이지 목적지에 이름을 붙이는 모든 패키지가 번호 매기기 스타일을 키로 쓰기 때문인데, 같은 스타일로 "1"인 페이지가 두 개면 목적지가 중복됩니다. 앞부분은 로마자, 본문은 아라비아로 — \pagenumbering{roman}, 그다음 \clearpage, 그다음 \pagenumbering{arabic} — 두 이름 공간을 떨어뜨려 놓는 형태가 이것입니다.
특별 권한을 가진 남은 카운터는 enumi에서 enumiv입니다: 커널은 네 개의 중첩 목록 수준만 지원하고 그 이상은 없으며, 각각에 표현 매크로 \theenumi에서 \theenumiv까지, 라벨 매크로 \labelenumi에서 \labelenumiv까지 붙어 있죠. 다섯 번째 enumerate는 조용한 오버플로가 아니라 Too deeply nested라는 오류입니다. \labelenumii를 \emph{(\theenumii)}로 다시 정의하면 인쇄되는 라벨이 바뀌고, \theenumii는 그 항목에 대한 \ref이 생산하는 것 — 그 라벨 대 참조 값 쌍이 바로 \p@ 이야기의 한 층 아래입니다.
엉뚱하게 동작하는 카운터 디버깅
네 개의 질문이 거의 모든 번호 불평에 답하고, 소스가 아니라 로그에게 물으면 됩니다. 날것 값은 무엇인가요? \typeout{COUNT = \number\value{exercise}}는 \the를 통째로 우회해 정수 자체를 찍어요. 인쇄되는 형태는 무엇인가요? \typeout{\meaning\theexercise}는 정의를 보여 주는데, 빠져 있는 부모 접두사가 바로 여기서 드러나죠. 초기화 목록에는 무엇이 있나요? \typeout{\meaning\cl@chapter}은 자식들을 \@elt {equation}\@elt {figure}... 형태로 나열합니다. aux 파일에는 무엇이 들어갔나요? .aux를 열어 \newlabel 줄을 읽으면 됩니다.
세 가지 실패와 그 서명. 잘못된 객체 종류를 찍는 참조는 라벨이 방금 \refstepcounter가 실행되지 않은 자리에 서 있다는 뜻이니, 여러분 카운터를 밟는 명령 뒤에다 옮기세요. 페이지에서는 맞는데 \ref에서 틀린 번호는 \thefoo와 \p@foo가 서로 다른 말 한다는 뜻이고, 패키지나 오래된 템플릿이 그중 하나를 다시 정의했는지 확인하면 됩니다. 초기화되지 않는 번호 매기기는 부모 관계가 \newcounter{foo}[parent]로 표현됐는데 문서에서 부모가 \stepcounter가 아니라 \setcounter로 밟히는 경우입니다 — 손으로 설정한 장은 아무것도 초기화하지 않아요.
그리고 클래스를 쓸 때는: 카운터는 맨 위에서 한 번, 초기화 부모와 표현과 함께 선언하고, 필요하지 않은 한 \p@와 \theH 매크로는 건드리지 않는 편이 낫습니다. 카운터 체계는 LaTeX에서 흥미 없는 해답이 동시에 옳은 해답인 몇 안 되는 곳 중 하나입니다.
이 강의 요약표
각 소절의 핵심 코드 한 줄씩. 소절 제목을 눌러 해당 위치로 이동하고 코드는 바로 복사하세요.
n_{\text{print}} = (n_{\text{parent}},\ n_{\text{raw}}) \qquad (2,4) \mapsto 2.4
\documentclass[11pt,a4paper]{article}
c_{\text{child}} \leftarrow 0 \quad \text{whenever} \quad c_{\text{parent}} \leftarrow c_{\text{parent}} + 1
\documentclass[12pt,a4paper]{report}
자주 하는 실수
\newcounter{foo}[section]이 번호를2.1로 찍게 하리라 기대하는 일. 선택 인자는 초기화만 등록하므로 여전히\renewcommand{\thefoo}{\thesection.\arabic{foo}}이 필요하고, 둘 다 하는\counterwithin{foo}{section}를 쓸 수도 있습니다.- 번호 매기는 환경을
\stepcounter로 만드는 일. 번호는 올바르게 보이지만\label/\ref는 앞의 카운터를 잡습니다. 참조될 환경은\refstepcounter를 호출해야 해요. \usecounter{enumi}을 쓰는 목록 앞에\setcounter{enumi}{4}를 적는 일.\usecounter가 카운터를 스스로 0으로 만들므로\setcounter는 그 뒤에, 목록 설정 인자 안에 두세요.\pagenumbering{...}을 쓰지 않고\thepage를 손으로 다시 정의하는 일.\pagenumbering은 1로 되돌리기까지 하고, 더 중요하게는 페이지 목적지가 어느 이름 공간에 사는지 hyperref에게 알려 줍니다.- 여러분이 발명한 카운터를
\autoref나\cref이 알리라 기대하는 일: hyperref에는\exerciseautorefname, cleveref에는\crefname과\Crefname을 모두 정의하세요. 그렇지 않으면 맨 번호나??를 얻게 됩니다. - 부모를
\setcounter로 초기화하면서 자식은 왜 계속 세는지 의아해하는 일. 초기화는\stepcounter에서 발동하고\setcounter에서는 발동하지 않습니다.
이 강의에 대한 질문
stepcounter와 refstepcounter의 차이는 무엇인가요?
\stepcounter는 레지스터를 올리고 자식들을 초기화합니다. \refstepcounter는 같은 일을 한 뒤 현재 인쇄 형태를 \@currentlabel에, 그리고 \@currentHref와 \@currentcounter까지 저장하는데, 그것이 뒤따르는 \label이 기록하는 문자열이에요. 누군가 여러분의 카운터를 \ref로 가리킨다면 \refstepcounter여야 합니다.섹션이 시작될 때 카운터를 초기화하려면 어떻게 하나요?
\newcounter{foo}[section]로 하거나, 나중에 \counterwithin{foo}{section}를 쓰면 됩니다. 2018년에 커널에 들어간 형태는 두 일을 모두 해요: \counterwithin은 초기화를 등록할 뿐 아니라 \thefoo를 \thesection.arabic(foo)로 다시 정의해 인쇄 번호가 섹션 접두사를 갖게 만듭니다. \newcounter는 초기화만 등록하죠. 구설치에서는 chngcntr 패키지를 로드해 같은 두 명령을 얻으세요.amsthm 없이도 저만의 환경에 번호를 매길 수 있나요?
\newcounter{exercise}[section], \renewcommand{\theexercise}{\thesection.\arabic{exercise}}, 그리고 시작 코드에서 \refstepcounter{exercise}를 호출해 \textbf{Exercise \theexercise.}를 조판하는 \newenvironment 하나. amsthm이 더하는 것은 공유 카운터와 스타일, 선택 이름 인자 같은 편의이지 마법이 아닙니다.list에서 usecounter는 무슨 일을 하나요?
\begin{list}의 설정 인자 안에서 \item이 어떤 카운터를 밟고 내부 \label이 어떤 카운터를 가리킬지 선언하죠. 정의의 마지막 부분이 \setcounter{#1}\z@이므로, 목록이 시작될 때 그 카운터를 0으로 되돌리는 일도 함께 합니다.제 카운터가 PDF 북마크나 링크에서 사라지는 이유는 무엇인가요?
\theH<counter>에서 만들어지는데 기본값이 맨 정수라 장 사이에서 충돌하기 때문입니다. \renewcommand{\theHexercise}{\thechapter.\arabic{exercise}}처럼 더 구체적으로 다시 정의하고, 로그에서 중복 목적지 경고를 확인하세요.\ref이 제목과 다른 문자열을 찍게 하려면 어떻게 하나요?
\the<counter> 앞에 붙으므로, \thesolution은 페이지에서 짧게 유지하면서 \ref{sol:x}는 섹션 접두사를 달고 나오게 할 수 있어요. 명사는 한 층만 소유하게 하세요, 그렇지 않으면 \autoref가 두 번 찍습니다.실시간 놀이터: LaTeX를 편집하고 바로 렌더링
입력하면 미리보기가 즉시 갱신됩니다. 일부러 깨뜨려서 오류가 어떻게 보이는지도 확인해 보세요.
이어서 읽기
같은 주제로 들어가는 세 갈래: 표기 자체, 그것을 가르치는 강의, 그리고 실제로 쓰는 글.