15

I want to write full names of authors in the LaTeX source, but assign different roles to them, and then via macro decide whether to print the full first name or just initials:

In the work of \artist{Iannis Xenakis}, as analysed by \researcher{John Doe}.

I think in the end I want as output:

In the work of Iannis Xenakis, as analysed by J Doe.

But I might want J. Doe or John Doe or just Doe -- and I want to keep this decision open, therefore the macros...

I am using biblatex, but I don't want to use \citeauthor because often the mentions are not directly related to a particular paper cited. Nevertheless, maybe I can reuse some macros that come with biblatex?


Here is my idea: I see that \DeclareNameFormat might provide a good way to define custom formats. But how would a macro using such a format to insert the name into the text look like? Might I use \citename{⟨key⟩}[⟨format⟩]{⟨name list⟩}? I understand that name list would be my source name as above, but what should I use as key?

9

You could add dummy bibentries in your bib file (and add options = {dataonly=true}, to ensure that they are not included in the bibliography or used for label creation). Based on that, you can use either \citename as suggested in your question or for convenience create a custom macro (say, \formatname) that will save you specifying author as required name list.

\documentclass{article}

\usepackage{biblatex}

\DeclareNameFormat{firstinits-last}{%
  \usebibmacro{name:first-last}{#1}{#4}{#5}{#7}%
  \usebibmacro{name:andothers}}

\DeclareNameAlias{artist}{first-last}
\DeclareNameAlias{researcher}{firstinits-last}

\newcommand*{\formatname}[2]{%
  \citename{fn#1}[#2]{author}%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{Doe12,
  author = {Doe, John},
  year = {2012},
  title = {A macro for formatting names},
}
@misc{fnDoe,
  options = {dataonly=true},
  author = {Doe, John},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\formatname{Doe}{artist}

\formatname{Doe}{researcher}

\printbibliography

\end{document}

enter image description here

5
  • Thank you. Although some extra effort due to creating bib entries for all names, I like this approach, because I can reuse the formatting options from biblatex. – Emit Taste May 28 '12 at 17:20
  • It should be possible to use existing entry keys of those authors -- but right now, I don't know how to switch off any kind of tracking if one uses \citename for those keys. "Dummy" entries are at least a safe solution. – lockstep May 28 '12 at 17:33
  • With this approach, John Doe is added to the reference list... Is it possible to exclude it from the reference list. Note that the options = {dataonly=true}, does not seems to work... – Denis Cousineau Feb 13 '16 at 2:08
  • I have found that if the bibtex entry is defined as type @customa (or any of the customa to customf type) instead of @misc, then it is possible ot generate the reference list EXCLUDING this type with \printbibliography[nottype=customa] – Denis Cousineau Feb 23 '16 at 3:20
  • 1
    Note that with the latest version of biblatex (beyond january 2016), this answer must be adapted; see tex.stackexchange.com/questions/299036/… for the corrections needed. – Denis Cousineau Mar 17 '16 at 0:32
12

Here is an idea not using biblatex at all:

\documentclass{article}

\makeatletter
% define the styles for the first name; these are going to be the values
% for the optional argument of \NewNameType;
% \@style => \NewNameType[style]{<csname>}
\def\@fullname#1\q@stop{#1~}
\def\@initial#1#2\q@stop{#1~}
\def\@initialdot#1#2\q@stop{#1.~}
\def\@noname#1\q@stop{}

% define the user command; the optional arguments sets the format;
% I chose `initial' as default:
\newcommand*\NewNameType[2][initial]{%
  \expandafter\newcommand\expandafter*\csname#2\endcsname[1]{\@nameuse{#2@aux}##1\q@stop}%
  \@namedef{#2@aux}##1 ##2\q@stop{\@nameuse{@#1}##1\q@stop##2}}
\makeatother

% define some styles:
\NewNameType{researcher}           % J Doe
\NewNameType[fullname]{artist}     % John Doe
\NewNameType[noname]{baker}        % Doe
\NewNameType[initialdot]{musician} % J. Doe

\begin{document}

\researcher{John Doe} \par
\artist{John Doe} \par
\baker{John Doe} \par
\musician{John Doe}

\end{document}

enter image description here

Additional styles could easily be added.

7
  • I liked (and upvoted) your's, too. – lockstep May 28 '12 at 17:22
  • @lockstep likewise :) – cgnieder May 28 '12 at 17:27
  • I've already hit the rep cap for today, but thanks anyway. :-) – lockstep May 28 '12 at 17:30
  • What about names with initials? Like "John Q. Doe" – Guillermo Garza Feb 13 '14 at 17:36
  • 1
    @MemoGarza that would require a little bit more work. Since biblatex has implementations for this the other answer probably already does support those kinds of names – cgnieder Feb 16 '14 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.
https://tex.stackexchange.com/questions/57636/macro-for-formatting-names-initials-or-full-name
tex.stackexchange.com
crawl=CC-MAIN-2021-31
190127
application/http; msgtype=response
sha1:NYPKW6UDZUAWE3RM2543QQXNJBJVOLST
<urn:uuid:b760b15e-65a3-43b0-8dc4-7423d553c2ed>
2021-08-02T06:34:27Z
151.101.129.69
text/html
sha1:JB7J3LC3YDNVTVLFLB4PY4MYWRLI5TOZ
<urn:uuid:c3c71dfb-e5bd-48b6-8c45-7bc232d8a1f4>
https://tex.stackexchange.com/questions/57636/macro-for-formatting-names-initials-or-full-name
response
<urn:uuid:8c1de475-56e7-4f6d-ad98-da6bf0b61bd2>
isPartOf: CC-MAIN-2021-31
publisher: Common Crawl
description: Wide crawl of the web for July/August 2021
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-67-67-148.ec2.internal
software: Apache Nutch 1.18 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.2-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: https://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/