\author
일반적으로 매크로에 선언된 이름 작성자의 정보를 가져와 이를 이름, 중간 이름, 성의 세 부분으로 나눌 수 있는 매크로를 만들고 싶습니다 . 이를 위해 \firstname
, \midlename
및 유형의 내부 매크로를 \lastname
생성할 수 있습니다. 그러면 매크로는 이 정보를 가져와 성, 이름, 중간 이름 형식으로 인쇄할 수 있습니다. 예를 들어, 이름 \author{Alexsandro Lucena Mota}
과 매크로를 선언하면 \newauthorname
pdf 문서에 이름이 형식으로 인쇄됩니다 Mota, Alexsandro Lucena
.
참고: \newauthorname
매크로는 단지 제안일 뿐이며 아마도 최고는 아닐 수도 있습니다. 여기서는 참고문헌 인용에서 저자명을 언급하려는 의도인데, 위에서 제시한 예시의 형태, 즉 Mota, Alexsandro Lucena
. 아마도 이 매크로에 대한 더 나은 이름은 이지만 \authornameinbibliographycitation
확실히 매우 깁니다. 자유롭게 제안해 주십시오.
이 작업을 수행할 수 있는 알려진 패키지나 매크로가 있습니까?
누군가가 여전히 "이게 왜 필요한가요?"라고 묻는 것이 가능합니다.
브라질에서는 논문의 표지 뒤에 아래 예시와 같이 카탈로그 데이터를 알려주어야 합니다.
그래서 LaTeX에서는 위 그림의 예와 같은 형식으로 작성자 이름을 출력해 주었으면 합니다.
하지만 누군가는 여전히 이렇게 묻습니다. 왜 손으로 쓰지 않나요?
\author
그리고 대답은 사용자가 매크로에 자신의 이름을 입력하는 것에 대해서만 걱정하고 LaTeX가 나머지를 처리하여 파일을 자동으로 생성하도록 패키지를 만들고 싶다는 것입니다 .
그리고 마지막으로 누군가는 최소한의 예시를 요구할 것이고, 그런 이유로 시식을 위한 코드를 따르게 될 것입니다.
\documentclass[12pt,a4paper]{memoir}
\usepackage{lastpage}
\title{Ficha catalográfica: um exemplo mínimo.}
\author{Alexsandro Lucena Mota}
\date{2020}
\begin{document}
\thispagestyle{empty}\null\vfill%
\begin{SingleSpacing}
\begin{center}
\begin{minipage}[c][][c]{13.5cm}
\begin{center}
{\small Ficha gerada por meio do SIGAA/Biblioteca
com dados fornecidos pelo
autor.}%
{\small N\'ucleo Integrado de Bibliotecas/UFMA}%
\end{center}
\end{minipage}
%
\begin{tabular}
[c]{|c|}\hline
\begin{minipage}[c][7.8cm][c]{13.1cm}%
\begin{adjustwidth}{0.5cm}{0.0cm}%
\texttt{Mota, Alexsandro
Lucena}\newline\texttt{\hspace*{0.55cm}\thetitle/
\theauthor. -- \thedate}
\newline\texttt{\hspace*{0.55cm}\pageref{LastPage}
p.}
\newline\newline\texttt{\hspace*{0.55cm}Orientador:
Prof. Dr. Fulando
Beltrano Silva Sauro.}
\newline\hspace{0.55cm}\texttt{Tese
(doutorado)~--~Programa de Pós-Graduação em
Física/ccet, Universidade Federal
do Maranhão, São Luís,
\thedate.}\newline\newline\texttt{\hspace*{0.55cm}1.
Ficha Catalográfica.~2. Exemplo Mínimo.~3.
LaTeX.~4. PDFLaTeX~I. Sauro, Fulando
Beltrano
Silva.~II. Título}
\end{adjustwidth}%
\end{minipage}%
\\\hline
\end{tabular}
\end{center}
\end{SingleSpacing}
\end{document}
위의 코드는
따라서 가능한 답변을 안내할 수 있는 충분한 정보를 제공하였기를 바랍니다.
답변1
암시적 정보를 추출하는 명령을 제공할 때 나타나는 문제는 \author
올바른 경우가 너무 많다는 것입니다. 이상적으로는 다음 각 사용 사례에 올바르게 대처해야 합니다.
\author{Alexsandro Lucena Mota}
\author{Doe}
\author{Jane Doe}
\author{Jane Maria Doe}
\author{Jane Maria Ellen Doe}
\author{Jane Maria de Lucca}
\author{Mota, Alexsandro Lucena}
처음 5개 사례를 처리하는 것은 매우 간단합니다. 사례 6에서는 모든 언어의 모든 다중 단어 성에 대한 지식을 구축해야 합니다. 사례 7에 대처하는 것은 가능하지만 지루합니다. 물론 만다린어와 같은 일부 언어에서는 성을 먼저 쓰는 역순으로 이름을 쓰기 때문에 더 많은 문제가 있습니다.
이러한 문제를 모두 무시하고 아래 코드는 을 설정하고 \Author
해당 인수를 명령에 전달하는 명령을 \firstname
정의 합니다 . 아래 이미지에서 볼 수 있듯이 사례 1~6을 충족하며 사례 6에는 . 이 명령은 Case 7에서는 잘 작동하지 않습니다.\middlename
\lastname
\author
~
\Author
코드는 다음과 같습니다.
\documentclass[12pt,a4paper]{memoir}
\parindent0pt
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \g_firstname_tl
\tl_new:N \g_middlename_tl
\tl_new:N \g_lastname_tl
\seq_new:N \l_author_names_seq
\NewDocumentCommand\Author{m}{
\author{#1}
% clear the first, middle and last token lists
\tl_clear:N \g_firstname_tl
\tl_clear:N \g_middlename_tl
\tl_clear:N \g_lastname_tl
% trim spaces and split the author name(s) on surrounding spaces
\regex_split:nxN {\s+} { \tl_trim_spaces:n {#1} } \l_author_names_seq
\int_case:nnF {\seq_count:N \l_author_names_seq }
{
{0} {}
{1} {\seq_pop_left:NN \l_author_names_seq \g_lastname_tl }
{2} {
\seq_pop_left:NN \l_author_names_seq \g_firstname_tl
\seq_pop_left:NN \l_author_names_seq \g_lastname_tl
}
}
{
\seq_pop_left:NN \l_author_names_seq \g_firstname_tl
\seq_pop_right:NN \l_author_names_seq \g_lastname_tl
\tl_gset:Nx \g_middlename_tl { \seq_use:Nn \l_author_names_seq {\space} }
}
}
\cs_generate_variant:Nn \regex_split:nnN { nxN }
\NewDocumentCommand\firstname{}{\tl_use:N\g_firstname_tl}
\NewDocumentCommand\middlename{}{\tl_use:N\g_middlename_tl}
\NewDocumentCommand\lastname{}{\tl_use:N\g_lastname_tl}
\NewDocumentCommand\fullauthor{}{\lastname,\space\firstname\space\middlename}
\ExplSyntaxOff
\newcommand\Names[1]{\Author{#1}\textsf{Author:} #1.\newline \textit{First}: \firstname, \textit{Middle}: \middlename, \textit{Last}: \lastname.\par\medskip}
\begin{document}
\Names{Alexsandro Lucena Mota}
\Names{Doe}
\Names{Jane Doe}
\Names{Jane Maria Doe}
\Names{Jane Maria Ellen Doe}
\Names{Jane Maria de~Lucca}
\textbf{Fails}:
\Names{Mota, Alexsandro Lucena}
\end{document}
아이디어는 매우 간단합니다.LaTeX3 정규 표현식저자 이름을 공백으로 분할한 다음 마지막 "이름"을 성으로 설정하고 나머지 이름을 이름으로 설정한 다음 남은 이름이 중간 이름이 됩니다. 매크로 는 수행하는 \Names
작업을 보여주는 도우미 매크로일 뿐입니다 \Author
.
코드는 \fullauthor
인쇄하는 명령을 제공합니다 last name, first name middle name
. 나 이거 부른거 아닌데\newauthorname
. 왜냐하면 나에게는 이것이 당신이 사용하는 명령처럼 들리기 때문입니다.정의하다작성자님, 인쇄하지 마세요.
편집하다
의견에서 요청한 대로 \author
새 명령을 정의하는 대신 명령을 재정의하는 작은 변형이 있습니다 \Author
. 이것이 자주 사용된다면 서문의 코드를 스타일 파일에 넣은 fullauthor.sty
다음 \usepackage{fullauthor}
.
\documentclass[12pt,a4paper]{article}
\parindent0pt
\let\realAuthor\author
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \g_firstname_tl
\tl_new:N \g_middlename_tl
\tl_new:N \g_lastname_tl
\seq_new:N \l_author_names_seq
\renewcommand\author[1]
{
\realAuthor{#1}
% clear the first, middle and last token lists
\tl_clear:N \g_firstname_tl
\tl_clear:N \g_middlename_tl
\tl_clear:N \g_lastname_tl
% trim spaces and split the author name(s) on surrounding spaces
\regex_split:nxN {\s+} { \tl_trim_spaces:n {#1} } \l_author_names_seq
\int_case:nnF {\seq_count:N \l_author_names_seq }
{
{0} {}
{1} {\seq_pop_left:NN \l_author_names_seq \g_lastname_tl }
{2} {
\seq_pop_left:NN \l_author_names_seq \g_firstname_tl
\seq_pop_left:NN \l_author_names_seq \g_lastname_tl
}
}
{
\seq_pop_left:NN \l_author_names_seq \g_firstname_tl
\seq_pop_right:NN \l_author_names_seq \g_lastname_tl
\tl_gset:Nx \g_middlename_tl { \seq_use:Nn \l_author_names_seq {\space} }
}
}
\cs_generate_variant:Nn \regex_split:nnN { nxN }
\NewDocumentCommand\firstname{}{\tl_use:N\g_firstname_tl}
\NewDocumentCommand\middlename{}{\tl_use:N\g_middlename_tl}
\NewDocumentCommand\lastname{}{\tl_use:N\g_lastname_tl}
\NewDocumentCommand\fullauthor{}{\lastname,\space\firstname\space\middlename}
\ExplSyntaxOff
\newcommand\Names[1]{\author{#1}\textsf{Author:} #1.\newline \textit{First}: \firstname, \textit{Middle}: \middlename, \textit{Last}: \lastname.\par\medskip}
\author{Alexsandro Lucena Mota} % using the new \author command in the preamble
\begin{document}
\fullauthor
\Names{Alexsandro Lucena Mota}
\Names{Doe}
\Names{Jane Doe}
\Names{Jane Maria Doe}
\Names{Jane Maria Ellen Doe}
\Names{Jane Maria de~Lucca}
\textbf{Fails}:
\Names{Mota, Alexsandro Lucena}
\end{document}
답변2
여기서는 @Andrew가 제공한 위 답변의 코드를 기반으로 한 답변을 제공합니다.
\documentclass[12pt,a4paper]{memoir}
\parindent0pt
\usepackage{lastpage}
\usepackage{xparse}
\let\realAuthor\author
\usepackage{xparse}
\ExplSyntaxOn
%\let\__real_author:n \author
\tl_new:N \g_firstname_tl
\tl_new:N \g_middlename_tl
\tl_new:N \g_lastname_tl
\seq_new:N \l_author_names_seq
\renewcommand\author[1]
{
%\realAuthor{#1}
% clear the first, middle and last token lists
\tl_clear:N \g_firstname_tl
\tl_clear:N \g_middlename_tl
\tl_clear:N \g_lastname_tl
% trim spaces and split the author name(s) on surrounding spaces
\regex_split:nxN {\s+} { \tl_trim_spaces:n {#1} }
\l_author_names_seq
\int_case:nnF {\seq_count:N \l_author_names_seq }
{
{0} {}
{1} {\seq_pop_left:NN \l_author_names_seq \g_lastname_tl }
{2} {
\seq_pop_left:NN \l_author_names_seq \g_firstname_tl
\seq_pop_left:NN \l_author_names_seq \g_lastname_tl
}
}
{
\seq_pop_left:NN \l_author_names_seq \g_firstname_tl
\seq_pop_right:NN \l_author_names_seq \g_lastname_tl
\tl_gset:Nx \g_middlename_tl { \seq_use:Nn
\l_author_names_seq {\space} }
}
}
\cs_generate_variant:Nn \regex_split:nnN { nxN }
\NewDocumentCommand\firstname{}{\tl_use:N\g_firstname_tl}
\NewDocumentCommand\middlename{}{\tl_use:N\g_middlename_tl}
\NewDocumentCommand\lastname{}{\tl_use:N\g_lastname_tl}
\NewDocumentCommand\theauthor{}{
\firstname\space\middlename\space\lastname}
\NewDocumentCommand\fullauthor{}{\lastname,
\space\firstname\space\middlename}
\ExplSyntaxOff
\title{Ficha catalográfica: um exemplo mínimo.}
\author{Alexsandro Lucena Mota} % using the new \author command
%in the preamble
\date{2020}
\begin{document}
\thispagestyle{empty}\null\vfill%
\theauthor\par\fullauthor
\begin{SingleSpacing}
\begin{center}
\begin{minipage}[c][][c]{13.5cm}
\begin{center}
{\small Ficha gerada por meio do
SIGAA/Biblioteca
com dados fornecidos pelo autor.\par%
N\'ucleo Integrado de Bibliotecas/UFMA}%
\end{center}
\end{minipage}
%
\begin{tabular}
[c]{|c|}\hline
\begin{minipage}[c][7.8cm][c]{13.1cm}%
\begin{adjustwidth}{0.5cm}{0.0cm}%
\texttt{\fullauthor}\newline\texttt{\hspace*{0.55cm}\thetitle/
\theauthor. -- \thedate}
\newline\texttt{\hspace*{0.55cm}\pageref{LastPage}
p.}
\newline\newline\texttt{\hspace*{0.55cm}Orientador:
Prof. Dr. Fulando
Beltrano Silva Sauro.}
\newline\hspace{0.55cm}\texttt{Tese
(doutorado)~--~Programa de
Pós-Graduação em
Física/ccet, Universidade Federal
do Maranhão, São Luís,
\thedate.}\newline\newline\texttt{\hspace*{0.55cm}1.
Ficha Catalográfica.~2. Exemplo
Mínimo.~3.
LaTeX.~4. PDFLaTeX~I. Sauro, Fulando
Beltrano
Silva.~II. Título}
\end{adjustwidth}%
\end{minipage}%
\\\hline
\end{tabular}
\end{center}
\end{SingleSpacing}
\end{document}
이 코드는 정확히 원하는 답변을 생성합니다.