<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Zaichuan Du</title>
<description>Blog posts by Zaichuan Du</description>
<generator>Emacs webfeeder.el</generator>
<link>https://zaichuan.net/</link>
<atom:link href="https://zaichuan.net/rss.xml" rel="self" type="application/rss+xml"/>
<lastBuildDate>Wed, 02 Dec 2026 18:36:41 +0000</lastBuildDate>
<item>
  <title>Customize BibTex citation keys with Emacs</title>
  <description><![CDATA[<div id="content" class="content">
 <p>
A BibTeX citation key is the short identifier that connects a citation in a
document to an entry in a bibliography. The same paper can arrive with quite
different keys depending on where its BibTeX entry was downloaded. A
consistent naming convention makes those keys easier to recognize when reading
or editing the manuscript.
</p>

 <p>
Tools such as  <a href="https://www.zotero.org/">Zotero</a> and  <a href="https://docs.jabref.org/">JabRef</a> can organize references and generate citation
keys. Zotero organizes a reference library, while its  <a href="https://retorque.re/zotero-better-bibtex/citing/">Better BibTeX extension</a>
provides customizable citation-key generation and  <a href="https://retorque.re/zotero-better-bibtex/exporting/auto/">automatic bibliography
exports</a>. JabRef works directly with BibTeX and BibLaTeX files and includes a
 <a href="https://docs.jabref.org/setup/citationkeypatterns">configurable key generator</a>. As an emacser, I prefer to manage my references
inside Emacs, where its packages offer several options.  <a href="https://joostkremers.github.io/ebib/">Ebib</a> provides an
interface for browsing and editing bibliography databases.  <a href="https://github.com/emacs-citar/citar">Citar</a> lets you
search references, insert citations, and open associated files and notes from
the minibuffer.  <a href="https://github.com/jkitchin/org-ref">Org-ref</a> combines citation and cross-reference support in Org
with BibTeX utilities.
</p>

 <p>
For my workflow, Emacs's built-in tools are enough. I mostly use LaTeX
commands for cross-references ( <a href="https://ctan.org/pkg/cleveref">\Cref</a> is is a favorite). RefTeX and Org’s
citation support cover my everyday needs. I do not need a separte interface
for browsing the bibliography. I keep my references in one plain-text
 <i>refs.bib</i> file and use the built-in  <code>bibtex-mode</code> to browse, search and edit
it.
</p>

 <p>
An essential part left to fix is, back to what we start with in this blog, a
consistent automatic key naming convention. The default settings of
 <code>bibtex-mode</code> produce longer keys than I want, making citations harder to scan
in my Org manuscripts. The function responsible is  <code>bibtex-generate-autokey</code>,
which Ebib also uses. My method customizes this existing mechanism: for one
author, I use the surname and year, such as Smith2026; for multiple authors, I
use their surname initials and year, such as SJ2026 for Smith and Jones.
</p>

 <p>
The code below implements that convention. After pasting a BibTex entry into
 <i>refs.bib</i>, place the cursor inside the entry and press  <code>C-u C-c C-c</code> to clean
it and regenerate its key. This command executes the Elisp function
 <code>(bibtex-clean-entry t)</code>. Once this configuration is loaded, the generated key
follows my naming convention.
</p>

 <div class="org-src-container">
 <pre class="src src-elisp"> <code> <span class="org-comment-delimiter">;; </span> <span class="org-comment">reftex configs for using \ref \Cref in the text.
</span>( <span class="org-keyword">setq</span> reftex-extra-bindings t)
( <span class="org-keyword">setq</span> reftex-ref-style-default-list '( <span class="org-string">&quot;Cleveref&quot;</span>))
( <span class="org-keyword">setq</span> reftex-use-multiple-selection-buffers t)

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">bibtex-mode configs for refs.bib.
</span>( <span class="org-keyword">setq</span> bibtex-align-at-equal-sign t)
( <span class="org-keyword">setq</span> bibtex-maintain-sorted-entries 'crossref)
( <span class="org-keyword">setq</span> bibtex-autokey-year-length 4)
( <span class="org-keyword">setq</span> bibtex-autokey-edit-before-use nil)
( <span class="org-keyword">setq</span> bibtex-entry-format t)  <span class="org-comment-delimiter">;; </span> <span class="org-comment">required by clean entry
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">automatic keys: first capital letters of authors' names + year
</span>( <span class="org-keyword">defun</span>  <span class="org-function-name">my/bibtex-generate-autokey</span> ()
   <span class="org-doc">&quot;Generate a citation key from author surnames and the year.&quot;</span>
  ( <span class="org-keyword">let*</span> ((names (mapcar #'bibtex-autokey-demangle-name
                        (split-string (bibtex-autokey-get-field  <span class="org-string">&quot;author&quot;</span>)  <span class="org-string">&quot;[ \t\n]+and[ \t\n]+&quot;</span>)))
         (name-key (mapconcat 'upcase (mapcar ( <span class="org-keyword">lambda</span> (name) (substring name 0 1)) names)))
         (year (bibtex-autokey-get-year)))
    ( <span class="org-keyword">if</span> (&gt; (length names) 1)
        (concat name-key year)
      (concat (capitalize (bibtex-autokey-get-names)) year))))

( <span class="org-keyword">with-eval-after-load</span> 'bibtex
  (advice-add 'bibtex-generate-autokey  <span class="org-builtin">:override</span> #'my/bibtex-generate-autokey))
</code></pre>
</div>

 <p>
 <a href="mailto:~zaichuan/blog@lists.sr.ht?subject=Re%3A%20Customize%20BibTeX%20citation%20keys%20with%20Emacs&amp;In-Reply-To=%3C87bj7zcu3a.fsf@zaichuan.net%3E">Comment by email</a>  <a href="https://lists.sr.ht/~zaichuan/blog.comments/%3C87bj7zcu3a.fsf@zaichuan.net%3E">Read the discussion</a>
</p>
</div>]]></description>
  <link>https://zaichuan.net/posts/2026-10-28.html</link>
  <guid isPermaLink="false">https://zaichuan.net/posts/2026-10-28.html</guid>
  <pubDate>Wed, 28 Oct 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>The First Post</title>
  <description><![CDATA[<div id="content" class="content">
 <p>
Hello World! This is the first blog I ever post in my first own webpage. The
motivation is that I need a place to write down and share ideas. Recently, I
find  <a href="https://sr.ht">Sourcehut</a> so cool and it meets my aesthetic pursuit of landing both codes
and brain storms. I am never fond of those social-media like hub for hosting
them, such as Github and Reddit. These two are good places for advertising your
accomplished projects, but never for organizing serious thinking.
</p>

 <p>
Writing chilly makes me quiet. Compared to writing a research paper, blogging
here and there calms me down. It also isolates you away from social-media
types of interactive writing. Thanks to LLM, sometimes I would rather let AI
to judge my writing and gives me some guidance. Peace and love with
machine. At least it does not hate, or does it?
</p>

 <p>
I have observed that individuals with a passion for technology or nerdy pursuits
commonly publish their initial blog posts on the topic of constructing or
self-hosting a static website–a trend in which I actively participate. Though I
have contemplated following suit, I have chosen to explore textual content as I
find a wealth of resources already available on website development. I am
currently honing my writing skills and aspire to consistently produce engaging
content. I often find that ideas which seem brilliant in thought often appear
more mundane once transcribed onto the screen.
</p>
</div>]]></description>
  <link>https://zaichuan.net/posts/2024-03-22.html</link>
  <guid isPermaLink="false">https://zaichuan.net/posts/2024-03-22.html</guid>
  <pubDate>Fri, 22 Mar 2024 00:00:00 +0000</pubDate>
</item>
</channel>
</rss>
