<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>
            
                    yasnippet on
                
            
            The Neo-Babbage Files</title>
        <link>https://babbagefiles.xyz/tags/yasnippet/</link>
        <description>Recent content  in yasnippet
            on The Neo-Babbage Files</description>
        <language>en-gb</language>
        
                <managingEditor>slade@lambda-y.net (Benjamin Slade)</managingEditor>
                <webMaster>slade@lambda-y.net (Benjamin Slade)</webMaster><lastBuildDate>Mon, 29 Dec 2025 11:00:32 +0000</lastBuildDate>
        <generator>Hugo -- gohugo.io</generator>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
            <atom:link href="https://babbagefiles.xyz/tags/yasnippet/index.xml" rel="self" type="application/rss&#43;xml" />
        
            
            <item>
                <title>Auto-generate “creator” PDF metadata in AUCTeX using yasnippet</title>
                <link>https://babbagefiles.xyz/auto-gen-hyperref-auctex-yasnippet/</link>
                
                
                <description>&lt;p&gt;After struggling with some poorly-handled, apparently &amp;ldquo;reset&amp;rdquo; proofs
introducing heaps of errors (despite my providing a &lt;code&gt;.tex&lt;/code&gt; source) for
the past few days,&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; I thought about providing automated pdf-tags
indicating creation tools used for my TeX-produced documents. Real,
professionally-typeset documents deserve to have the tools used to
produce them properly recognised in their metadata. So here&amp;rsquo;s a
yasnippet which generates auto-populated &lt;code&gt;hyperref&lt;/code&gt; options to
generate a &lt;code&gt;pdf-creator&lt;/code&gt; tag indicating the version of Emacs, AUCTeX,
and distro used:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-lisp&#34; data-lang=&#34;lisp&#34;&gt;&lt;span class=&#34;err&#34;&gt;#&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;-*-&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;mode:&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;snippet&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;-*-&lt;/span&gt;
&lt;span class=&#34;err&#34;&gt;#&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;name:&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;version-hyperref&lt;/span&gt;
&lt;span class=&#34;err&#34;&gt;#&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;key:&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;hyperv&lt;/span&gt;
&lt;span class=&#34;err&#34;&gt;#&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;--&lt;/span&gt;
&lt;span class=&#34;nv&#34;&gt;\usepackage[pdfusetitle,&lt;/span&gt;
 &lt;span class=&#34;nv&#34;&gt;pdfcreator={&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;`&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;replace-regexp-in-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;_&amp;#34;&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;-&amp;#34;&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;concat&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;replace-regexp-in-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;\n&amp;#34;&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;substring&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;emacs-version&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;1-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;cl-search&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;(&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;emacs-version&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
     &lt;span class=&#34;s&#34;&gt;&amp;#34; with AUCTeX &amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;pkg-info-version-info&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;&amp;#39;auctex&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
   &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;type -p lsb_release &amp;gt; /dev/null&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;concat&lt;/span&gt;
        &lt;span class=&#34;s&#34;&gt;&amp;#34; on &amp;#34;&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;substring&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lsb_release -sd&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lsb_release -sd&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
        &lt;span class=&#34;s&#34;&gt;&amp;#34; (&amp;#34;&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;substring&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lsb_release -sr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lsb_release -sr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
        &lt;span class=&#34;s&#34;&gt;&amp;#34; &amp;#39;&amp;#34;&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;substring&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lsb_release -sc&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lsb_release -sc&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
         &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#39;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34; release, using the &amp;#34;&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;replace-regexp-in-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;\n$&amp;#34;&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;uname -r&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34; kernel)&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
     &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;type -p guix &amp;gt; /dev/null&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
       &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;concat&lt;/span&gt;
         &lt;span class=&#34;s&#34;&gt;&amp;#34;on Guix System &amp;#34;&lt;/span&gt;
       &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;guix system -V | awk &amp;#39;NR==1{printf $5}&amp;#39;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
         &lt;span class=&#34;s&#34;&gt;&amp;#34; (using the &amp;#34;&lt;/span&gt;
       &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;replace-regexp-in-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;\n$&amp;#34;&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;shell-command-to-string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;uname -r&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34; kernel)&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))))&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;`&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;}]{hyperref}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Snippets can execute elisp code placed between &lt;code&gt;`...`&lt;/code&gt;. The version of
Emacs (with some of the additional less-relevant information removed
via &lt;code&gt;substring&lt;/code&gt; combined with &lt;code&gt;cl-search&lt;/code&gt; (for &amp;ldquo;(&amp;quot;, the beginning of
the additional information)), and AUCTeX can easily be done using
Emacs-internal functions, &lt;code&gt;(emacs-version)&lt;/code&gt; and
&lt;code&gt;(pkg-info-version-info &#39;auctex)&lt;/code&gt;, respectively.&lt;/p&gt;
&lt;p&gt;For the operating-system information, we rely on external calls to the
shell via Emacs&amp;rsquo;s &lt;code&gt;shell-command-to-string&lt;/code&gt; function. Many distros
will have &lt;code&gt;lsb_release&lt;/code&gt; application (from the &lt;a href=&#34;https://en.wikipedia.org/wiki/Linux%5FStandard%5FBase&#34;&gt;Linux Standard Base
project&lt;/a&gt;) available (and presumably usually part of the
base-install). Running &lt;code&gt;lsb_release --help&lt;/code&gt; reveals a helpful set of
options:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;SYNOPSIS
      lsb_release &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;OPTION&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;...
OPTIONS
      −v, −−version
      Display the version of the LSB specification against which the distribution is compliant.

      −i, −−id
      Display the string id of the distributor.

      −d, −−description
      Display the single line text description of the distribution.

      −r, −−release
      Display the release number of the distribution.

      −c, −−codename
      Display the codename according to the distribution release.

      −a, −−all
      Display all of the above information.

      −s, −−short
      Display all of the above information in short output format.

      −h, −−help
      Display this message.
LSB Version:	1.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And we can get various bits of information about the distribution out
via passing different flags to &lt;code&gt;lsb_release&lt;/code&gt; (combined with the &lt;code&gt;-s&lt;/code&gt;
&amp;ldquo;short description&amp;rdquo; flag).&lt;/p&gt;
&lt;p&gt;Some distros don&amp;rsquo;t use the &lt;code&gt;lsb_release&lt;/code&gt;, and looking at &lt;a href=&#34;https://github.com/dylanaraps/neofetch/blob/master/neofetch&#34;&gt;various
methods &lt;code&gt;neofetch&lt;/code&gt; employs to manage to suss out the distro&lt;/a&gt; was
instructive. I added a method to allow for detecting the version of
&lt;a href=&#34;https://www.gnu.org/software/guix/&#34;&gt;Guix System&lt;/a&gt; distribution, and it could be easily extended (in
neofetch-style) to employ other methods for additional distros. (But
the &lt;code&gt;lsb_release&lt;/code&gt; method should handle the majority of distros.)&lt;/p&gt;
&lt;p&gt;Finally, we get can the kernel version out via the ubiquitous &lt;code&gt;uname&lt;/code&gt;
application, via &lt;code&gt;uname -r&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Thus calling this snippet on &lt;a href=&#34;https://voidlinux.org/&#34;&gt;Void Linux&lt;/a&gt; results in a TeX block like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-latex&#34; data-lang=&#34;latex&#34;&gt;&lt;span class=&#34;k&#34;&gt;\usepackage&lt;/span&gt;[pdfusetitle,
pdfcreator=&lt;span class=&#34;nb&#34;&gt;{&lt;/span&gt;GNU Emacs 26.2 with AUCTeX 12.1.2 on Void Linux
(rolling &amp;#39;void&amp;#39; release, using the 5.1.5-1 kernel)&lt;span class=&#34;nb&#34;&gt;}&lt;/span&gt;]&lt;span class=&#34;nb&#34;&gt;{&lt;/span&gt;hyperref&lt;span class=&#34;nb&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(The &lt;code&gt;hyperref&lt;/code&gt; option &lt;code&gt;pdfusetitle&lt;/code&gt; will make use of the values of
the TeX-defined &lt;code&gt;\author{...}&lt;/code&gt; and &lt;code&gt;\title={...}&lt;/code&gt; commands to populate
the author and title pdf metadata. If you do anything funky with these
fields (like adding a &lt;code&gt;\thanks{...}&lt;/code&gt; command to your title), you may
need to take out the &lt;code&gt;pdfusetitle&lt;/code&gt; option and manually specify these
tags via &lt;code&gt;pdfauthor={...}&lt;/code&gt; etc.)&lt;/p&gt;
&lt;p&gt;On &lt;a href=&#34;https://www.gnu.org/software/guix/&#34;&gt;Guix System&lt;/a&gt; (née GuixSD) the result will be something like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-latex&#34; data-lang=&#34;latex&#34;&gt;&lt;span class=&#34;k&#34;&gt;\usepackage&lt;/span&gt;[pdfusetitle,
pdfcreator=&lt;span class=&#34;nb&#34;&gt;{&lt;/span&gt;GNU Emacs 26.2 with AUCTeX 12.1.2
on Guix System 1.0.1-1.8204295 (using the 5.1.2-gnu kernel)&lt;span class=&#34;nb&#34;&gt;}&lt;/span&gt;]&lt;span class=&#34;nb&#34;&gt;{&lt;/span&gt;hyperref&lt;span class=&#34;nb&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;An amusing side-discovery of putting this snippet together is that
&lt;a href=&#34;https://www.archlinux.org/&#34;&gt;Arch Linux&lt;/a&gt; multiply – and insistently – reminds the &lt;code&gt;uname&lt;/code&gt; caller of
the distro the kernel belongs to. I.e., using this snippet on my Arch
machine resulted in:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-latex&#34; data-lang=&#34;latex&#34;&gt; &lt;span class=&#34;k&#34;&gt;\usepackage&lt;/span&gt;[pdfusetitle,
pdfcreator=&lt;span class=&#34;nb&#34;&gt;{&lt;/span&gt;GNU Emacs 26.2 with AUCTeX 12.1.2 on
Arch Linux (rolling &amp;#39;n/a&amp;#39; release, using the 5.1.5-arch1-2-ARCH kernel)&lt;span class=&#34;nb&#34;&gt;}&lt;/span&gt;]&lt;span class=&#34;nb&#34;&gt;{&lt;/span&gt;hyperref&lt;span class=&#34;nb&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The horrifying reality of &amp;ldquo;professional&amp;rdquo; desktop publishing software stands in contrast to real professional documents produced in (La)TeX; and any resulting professionalism in the output of the former results from squeezing &lt;strong&gt;additional&lt;/strong&gt; unpaid labour from researchers who have to correct the errors of &amp;ldquo;professional&amp;rdquo; typesetters. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
                
                        <author>Benjamin.Slade@fakeEmailToMakeValidatorHappy.com (Benjamin Slade)</author>
                
                     
                        
                             
                            
                                
                                 
                                    <category domain="https://babbagefiles.xyz/categories/emacs">emacs</category>
                                 
                                    <category domain="https://babbagefiles.xyz/categories/latex">latex</category>
                                
                            
                        
                     
                        
                     
                        
                             
                            
                                
                                 
                                    <category domain="https://babbagefiles.xyz/tags/auctex">auctex</category>
                                 
                                    <category domain="https://babbagefiles.xyz/tags/yasnippet">yasnippet</category>
                                
                            
                        
                    
                
                <guid>https://babbagefiles.xyz/auto-gen-hyperref-auctex-yasnippet/</guid>
                <pubDate>Wed, 29 May 2019 22:59:00 -0600</pubDate>
            </item>
        
    </channel>
</rss>


