请帮忙:我正在编辑一个.tex
包含大量文本的文件(回忆录类),我想收集重要问题、引语、单词等句子,并将它们收集到各自的组中,并将它们放在书的末尾。
例如:
.tex
文件
\chapter{xyz}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam metus massa, molestie elementum tincidunt at, mollis et quam.
\collectQuestion{Donec viverra posuere lorem, ac sagittis eros tincidunt interdum?}
Phasellus feugiat id justo at pretium.
Duis sed commodo velit. \collectPhrase{Cras tempus} fermentum leo, ac congue nisl convallis vel.
\chapter{abc}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam metus massa, molestie elementum tincidunt at, mollis et quam.
Donec viverra posuere lorem, ac sagittis eros tincidunt interdum.
Phasellus feugiat id justo at pretium. \collectQuestion{Sed placerat sodales lorem sed sodales?}
Duis sed commodo velit. Cras tempus fermentum leo, \collectPhrase{ac congue nisl} convallis vel.
.pdf
文件 。 。 。
问题?
- Donec viverra posuere lorem,ac sagittis eros tincidunt interdum?..pg x
- Sed placerat sodales lorem sed sodales?..............................................pg y
短语:
- Cras tempus(第 x 页)
- ac congue nisl (pg y)
答案1
请原谅我略带讽刺的意味:
“回忆录课”作为回忆录的基本用户手册,它只有 611 页,其中说可以做这样的事情:
\documentclass{memoir}
%\usepackage{hyperref}
\newcommand{\listofphrasesname}{Phrases:}%
\newlistof{listofphrases}{phr}{\listofphrasesname}%
\newlistentry{phrase}{phr}{0}%
\cftpagenumbersoff{phrase}%
%
\newcounter{phrases}
\renewcommand{\thephrases}{\arabic{phrases}.}
\newcommand{\collectPhrase}[1]{%
#1%
\stepcounter{phrases}%
\addcontentsline{phr}{phrase}{\protect\numberline{\thephrases}#1~(pg~\thepage)}%
}
\newcommand{\listofquestionsname}{Questions?}%
\newlistof{listofquestions}{qst}{\listofquestionsname}%
\newlistentry{question}{qst}{0}%
\cftpagenumberson{question}%
%
\newcounter{questions}
\renewcommand{\thequestions}{\arabic{questions}.}
\newcommand{\collectQuestion}[1]{%
#1%
\stepcounter{questions}%
\addcontentsline{qst}{question}{\protect\numberline{\thequestions}#1}%
}
\makeatletter
\newlength\mypagenumwidth
\settowidth\mypagenumwidth{\@nameuse{cftquestionpagefont}pg~\hb@xt@\@pnumwidth{}}%
\renewcommand\cftquestionformatpnumhook[4]{%
\hb@xt@\mypagenumwidth{\hfil\@nameuse{cftquestionpagefont}pg~#1}%
}%
\makeatother
\begin{document}
\tableofcontents
\chapter{xyz}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
metus massa, molestie elementum tincidunt at, mollis et
quam. \collectQuestion{Donec viverra posuere lorem, ac sagittis
eros tincidunt interdum?} Phasellus feugiat id justo at pretium.
Duis sed commodo velit. \collectPhrase{Cras tempus} fermentum
leo, ac congue nisl convallis vel.
\chapter{abc}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
metus massa, molestie elementum tincidunt at, mollis et
quam. Donec viverra posuere lorem, ac sagittis eros tincidunt
interdum. Phasellus feugiat id justo at
pretium. \collectQuestion{Sed placerat sodales lorem sed
sodales?} Duis sed commodo velit. Cras tempus fermentum leo,
\collectPhrase{ac congue nisl} convallis vel.
\cleardoublepage
\listofquestions*
\listofphrases*
\end{document}
或者,您可以做一些事情来跟踪问题/短语/页面的数量的宽度,并将最宽的问题编号/短语编号/页码的宽度保存到标签中,以便在将来的 LaTeX 运行中检索该标签以设置//\cftqestionnumwidth
包含页码\cftphrasenumwidth
的宽度:\hbox
\documentclass{memoir}
%\usepackage{hyperref}
\makeatletter
\newcommand{\listofphrasesname}{Phrases:}%
\newlistof{listofphrases}{phr}{\listofphrasesname}%
\newlistentry{phrase}{phr}{0}%
\cftpagenumbersoff{phrase}%
%
\newcounter{phrases}
\renewcommand{\thephrases}{\arabic{phrases}.}
\newlength\maxphrasenumwidth
\setlength\maxphrasenumwidth{0pt}%
\newcommand{\collectPhrase}[1]{%
#1%
\stepcounter{phrases}%
\begingroup
\settowidth{\@tempdima}{\@nameuse{cftphrasepagefont}\thephrases~}%
\ifdim\@tempdima>\maxphrasenumwidth
\setlength\maxphrasenumwidth\@tempdima
\global\maxphrasenumwidth\maxphrasenumwidth
\fi
\endgroup
\addcontentsline{phr}{phrase}{%
\protect\numberline{\protect\hfill\thephrases\protect~}%
#1\protect~(pg\protect~\thepage)%
}%
}
\AtBeginDocument{%
\@ifundefined{r@maxphrasenumwidth}{%
\settowidth\cftphrasenumwidth{\@nameuse{cftphrasepagefont}100.~}%
}{%
\setlength\cftphrasenumwidth{\r@maxphrasenumwidth}%
}%
}%
\AtEndDocument{%
\immediate\write\@auxout{%
\string\newlabel{maxphrasenumwidth}{\the\maxphrasenumwidth}%
}%
}%
\newlength\mypagenumwidth
\newlength\mypagenumsep
\newcommand{\listofquestionsname}{Questions?}%
\newlistof{listofquestions}{qst}{\listofquestionsname}%
\newlistentry{question}{qst}{0}%
\cftpagenumberson{question}%
\newcounter{questions}
\renewcommand{\thequestions}{\arabic{questions}.}
\newlength\maxquestnumwidth
\setlength\maxquestnumwidth{0pt}%
\newlength\maxpagenumwidth
\setlength\maxpagenumwidth{0pt}%
\newcommand{\collectQuestion}[1]{%
#1%
\stepcounter{questions}%
\begingroup
\settowidth{\@tempdima}{\@nameuse{cftquestionpagefont}\thequestions~}%
\ifdim\@tempdima>\maxquestnumwidth
\setlength\maxquestnumwidth\@tempdima
\global\maxquestnumwidth\maxquestnumwidth
\fi
\settowidth{\@tempdima}{\@nameuse{cftquestionpagefont}pg~\thepage}%
\ifdim\@tempdima>\maxpagenumwidth
\setlength\maxpagenumwidth\@tempdima
\global\maxpagenumwidth\maxpagenumwidth
\fi
\endgroup
\addcontentsline{qst}{question}{%
\protect\numberline{\protect\hfill\thequestions\protect~}#1%
}%
}%
\AtBeginDocument{%
\settowidth\mypagenumsep{\@nameuse{cftquestionpagefont}m}%
\setlength\mypagenumsep{1.5\mypagenumsep}%
\@ifundefined{r@maxquestnumwidth}{%
\settowidth\cftquestionnumwidth{\@nameuse{cftquestionpagefont}100.~}%
}{%
\setlength\cftquestionnumwidth{\r@maxquestnumwidth}%
}%
\@ifundefined{r@maxpagenumwidth}{%
\settowidth\mypagenumwidth{%
\@nameuse{cftquestionpagefont}pg~\hb@xt@\@pnumwidth{}%
}%
}{%
\setlength\mypagenumwidth{\r@maxpagenumwidth}%
}%
\cftinsertcode{questionrightadjust}{%
\setpnumwidth{\mypagenumwidth}%
\setrmarg{\dimexpr\mypagenumsep+\mypagenumwidth\relax}%
}%
\cftinserthook{qst}{questionrightadjust}%
}%
\AtEndDocument{%
\immediate\write\@auxout{%
\string\newlabel{maxquestnumwidth}{\the\maxquestnumwidth}%
}%
\immediate\write\@auxout{%
\string\newlabel{maxpagenumwidth}{\the\maxpagenumwidth}%
}%
}%
\renewcommand\cftquestionformatpnumhook[4]{%
\hb@xt@\mypagenumwidth{\@nameuse{cftquestionpagefont}pg~#1\hfil}%
%\hb@xt@\mypagenumwidth{\@nameuse{cftquestionpagefont}pg\hfil#1}%
%\hbox{\@nameuse{cftquestionpagefont}pg~#1}%
}%
\makeatother
\begin{document}
\tableofcontents
\chapter{xyz}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
metus massa, molestie elementum tincidunt at, mollis et
quam. \collectQuestion{Donec viverra posuere lorem, ac sagittis
eros tincidunt interdum?} Phasellus feugiat id justo at pretium.
Duis sed commodo velit. \collectPhrase{Cras tempus} fermentum
leo, ac congue nisl convallis vel.
\chapter{abc}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
metus massa, molestie elementum tincidunt at, mollis et
quam. Donec viverra posuere lorem, ac sagittis eros tincidunt
interdum. Phasellus feugiat id justo at
pretium. \collectQuestion{Sed placerat sodales lorem sed
sodales?} Duis sed commodo velit. Cras tempus fermentum leo,
\collectPhrase{ac congue nisl} convallis vel.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\collectPhrase{ac congue nisl}.
\newpage\setcounter{page}{1000}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
metus massa, molestie elementum tincidunt at, mollis et quam.
\collectQuestion{Sed placerat sodales lorem sed
sodales?} \collectPhrase{Cras tempus} fermentum
leo, ac congue nisl convallis vel.
\cleardoublepage
\listofquestions*
\listofphrases*
\end{document}
答案2
如果你想把问题和短语写在最后,按照它们出现的顺序:
\documentclass[a4paper]{memoir}
\usepackage{xparse}
\makeatletter
\newcommand{\mdotfill}[1][1em]{%
\leavevmode
\linebreak[0]%
\mbox{}\nobreak
\cleaders \hb@xt@ .44em{\hss.\hss}\hskip #1 plus 1fill
\kern\z@
}
\makeatother
\ExplSyntaxOn
\NewDocumentCommand{\collectQuestion}{m}
{
\naib_collect:Nnn \g_naib_collect_question_seq { #1 } { \mdotfill }
}
\NewDocumentCommand{\collectPhrase}{m}
{
\naib_collect:Nnn \g_naib_collect_phrase_seq { #1 } { \nobreakspace }
}
\NewDocumentCommand{\printQuestions}{}
{
\begin{enumerate}
\seq_use:Nn \g_naib_collect_question_seq {}
\end{enumerate}
}
\NewDocumentCommand{\printPhrases}{}
{
\begin{enumerate}
\seq_use:Nn \g_naib_collect_phrase_seq {}
\end{enumerate}
}
\int_new:N \g_naib_collect_int
\seq_new:N \g_naib_collect_question_seq
\seq_new:N \g_naib_collect_phrase_seq
\cs_new_protected:Nn \naib_collect:Nnn
{
\int_gincr:N \g_naib_collect_int
\label{ naib @ \int_to_roman:n { \g_naib_collect_int } }
\naib_collect_append:Nenn
#1
{ naib @ \int_to_roman:n { \g_naib_collect_int } } % the generated label
{ #2 } % the text
{ #3 } % the separation
}
\cs_new_protected:Nn \naib_collect_append:Nnnn
{
\seq_gput_right:Nn #1 { \naib_collect_print:nnn {#2}{#3}{#4} }
}
\cs_generate_variant:Nn \naib_collect_append:Nnnn { Ne }
\cs_new_protected:Nn \naib_collect_print:nnn
{
\item #2#3(pg.\nobreakspace\pageref{#1})
}
\ExplSyntaxOff
\begin{document}
\chapter{xyz}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam metus massa, molestie elementum
tincidunt at, mollis et quam.\collectQuestion{Donec viverra posuere lorem, ac sagittis eros tincidunt
interdum feugiat?} Phasellus feugiat id justo at pretium. Duis sed commodo velit.\collectPhrase{Cras
tempus} fermentum leo, ac congue nisl convallis vel.
\chapter{abc}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam metus massa, molestie elementum
tincidunt at, mollis et quam. Donec viverra posuere lorem, ac sagittis eros tincidunt interdum.
Phasellus feugiat id justo at pretium. \collectQuestion{Sed placerat sodales lorem sed sodales?} Duis
sed commodo velit. Cras tempus fermentum leo, \collectPhrase{ac congue nisl} convallis vel.
\chapter{QP}
\section{Questions}
\printQuestions
\section{Phrases}
\printPhrases
\end{document}