Some TeX Developments

Coding in the TeX world

Archive for the ‘LaTeX’ Category

biblatex: numbered citations as footnotes

with one comment

Most chemistry journals use numbered citation styles, with all of the references appearing at the end of the article in a References section. However, there are some that place the references at the bottom of the page they occur on, as footnotes. This is a bit more awkward to achieve than a simple section, but as biblatex has all of the citation data available from the start of a document I thought it should be easy to do.

It turns out that biblatex has the very handy \footfullcite macro, which nearly does what is needed. This macro will print the reference as a footnote, but uses LaTeX’s footnote numbering system to do this. The result is that repeating citations, compressing several citations into a range and so on is not so easy. In the end, I decided to drop Philipp Lehman (the author of biblatex) an e-mail for some guidance. He came back with two approaches, one for citations in the text and one for superscript citations:

\documentclass{article}
\usepackage[style=numeric-comp]{biblatex}
\bibliography{biblatex-examples}
\makeatletter

\ExecuteBibliographyOptions{citetracker,sorting=none}

\DeclareCiteCommand{\notefullcite}[\mkbibbrackets]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{notefullcite}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

\newbibmacro*{notefullcite}{%
  \ifciteseen
    {}
    {\footnotetext[\thefield{labelnumber}]{%
       \usedriver{}{\thefield{entrytype}}.}}}
\DeclareCiteCommand{\superfullcite}[\cbx@superscript]%
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}}
  {\usebibmacro{citeindex}%
   \usebibmacro{superfullcite}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}}

\newbibmacro*{superfullcite}{%
  \ifciteseen
    {}
    {\xappto\cbx@citehook{%
       \noexpand\footnotetext[\thefield{labelnumber}]{%
         \fullcite{\thefield{entrykey}}.}}}}

\newrobustcmd{\cbx@superscript}[1]{%
  \mkbibsuperscript{#1}%
  \cbx@citehook
  \global\let\cbx@citehook=\empty}
\let\cbx@citehook=\empty

\makeatother
\begin{document}

Some filler text \notefullcite{cotton}, then some more text
\notefullcite{hammond}. Perhaps some more text and the same
citation again \notefullcite{hammond}. Yet another one
\notefullcite{knuth:ct:a}. Now all again
\notefullcite{cotton,hammond,knuth:ct:a}.

Some filler text,\superfullcite{augustine} then some more
text.\superfullcite{companion} Perhaps some more text and the
same citation again.\superfullcite{companion} Yet another
one.\superfullcite{kastenholz} Now all
again.\superfullcite{augustine,companion,kastenholz}

\end{document}

I might add this to my biblatex styles, but I’ll wait to see if Philipp puts the code or some notes into the biblatex core before I do. I should also point out that if you want footnote citations and other footnotes then you’ll need something like the bigfoot package to do the job. But this is a pretty good place to start from.

Written by Joseph Wright

March 8th, 2010 at 8:04 am

Posted in LaTeX, biblatex

Building biblatex-biber (again)

with 4 comments

I recently posted some information on building biblatex-biber. Since then, v0.5 of biblatex-biber has appeared and there are some positive changes. The code now creates its own file to grab the required Perl modules. So on Mac OS X (Snow Leopard) and Ubuntu (9.10) all I needed to do after downloading the source was

perl Build.PL
sudo ./Build installdeps
./Build
./Build test
sudo ./Build install

at the Terminal. The second step grabbed all of the modules needed and everything worked fine.

On Windows, life is still a bit complicated but I now can get things to work. A bit of a trawl on the Internet led to a blog post about Text::BibTeX. At the moment, the solution is still in beta and so there is a bit of work to do. With Strawberry Perl installed I went to the Command Prompt (as Administrator) and started the cpan program. At its prompt I did

install Config::AutoConf Capture::Tiny IPC::Run
install A/AM/AMBS/Text/Text-BibTeX-0.40_3.tar.gz

which all seemed to work. After downloading and unzipping the source for biblatex-biber (which is in .gz format, so use something like 7-Zip to open it), still as Administrator at the Command Prompt I did

perl build.pl
build installdeps
build
build test
build install

and everything worked. So I’ve finally got it working across all platforms. Hopefully the Text::BibTeX install will become easier when it moves from beta status.

Written by Joseph Wright

February 27th, 2010 at 7:55 am

Posted in LaTeX, biblatex

biblatex reaches v0.9

without comments

A couple of days ago biblatex v0.9 appeared on CTAN. As usual, there is a long list of changes, bug fixes and so on. The restrictions on inclusion in TeX distributions have been lifted, and so it’s already available in TeX Live. At the same time, biblatex-biber has been uploaded to CTAN, so hopefully ready to use versions will be added to the distributions at some point (MikTeX is likely to be first, I suspect).

I’ve just uploaded an updated version of biblatex-chem to CTAN, to keep in sync with the changes in biblatex. I’ll try to get biblatex-nature and biblatex-science done in soon (today) so that everything is working.

Written by Joseph Wright

February 16th, 2010 at 8:58 am

Posted in LaTeX, biblatex

siunitx version 2.0: alpha 1

without comments

I’ve been working on siunitx version 2, getting the code to the point where I’d hope it works for most things that the current release does. Over the last couple of weeks I hope I’ve sorted out the table issues which tend to be a problem in version 1, plus “mopped up” a few outstanding odds and ends. So it feels like an appropriate point for a public snap shot of the code. As progress has been good, I’m calling this one alpha 1.

At this stage, there are likely to be some bugs and other annoyances in the code. However, I hope that enough works for people to risk taking the plunge and trying it out. For those willing to try out siunitx v2.0, you can get:

You’ll need to have up to date installations of both expl3 and the xpackages to try out the code, as internally the new code uses the LaTeX3 internal syntax. The biggest change that users should see from version 1 is that I’ve re-thought the option names. They are mainly longer, but more informative, in the new code. Improvements to the names I’ve picked are of course welcome.

At this stage, I’m still working on adding more ideas to the code. So there are some omissions in the release that I know are there and am intending to sort out. Of course, different users have different priorities for improvement. That said, there are bound to be things which simply are broken, things I’ve forgotten and the odd item that I’m currently planning not to carry forward from version 1. Feedback by as comments here, by e-mail or at the BerliOS site is very welcome.

The current development plan is to see how much is wrong with the alpha code, and if necessary to have some more alpha-status snap shots. I’d then hope to have a beta some time in the spring (perhaps April or May), with a full release currently in my mind for June or July. Exactly how this will work out depends on other projects: I’d like, for example, to have some floating-point tools in siunitx, but for that I need to write them for LaTeX3. The feature list for the release certainly isn’t fixed, and I’d expect that once v2.0 is out there will continue to be more ideas to add on.

Written by Joseph Wright

January 31st, 2010 at 3:52 pm

Posted in LaTeX, siunitx

Tagged with , ,

Building biblatex-biber

with 17 comments

The biblatex-biber project provides probably the best way for biblatex users to switch to pure UTF-8 bibliography information. However, getting it to build can cause problems: biblatex-biber is a Perl programme, and needs various downloads from CPAN. I thought it would therefore be useful to put some simple recipes here, explaining what I’ve done to get a working biblatex-biber on Windows, Ubuntu and Mac OS X.  I’m assuming that the latest biblatex-biber release has been downloaded and unzipped somewhere, and that the Command Prompt/Terminal/Shell is open in that directory (folder).

Mac OS X 10.6 (Snow Leopard)

Mac OS X comes with Perl installed, so life is relatively easy. At the Terminal, you need to run the cpan script as root:

sudo cpan

The cpan script has its own prompt, but this is very similar to the Terminal one. First, I updated cpan itself and installed a helper module with

install CPAN
reload cpan
install YAML

That done, the various requirements for biblatex-biber can be installed, using the single call

install Data::Dump List::AllUtils Readonly Text::BibTeX Readonly::XS

For the more cautious person (such as me), each install instruction can be given on a separate line: this keeps things a bit more controlled. I accepted the standard settings, except when asked about installing items that were only needed for testing, where I said no.

Once cpan has done all of the installing, you can leave it by typing

exit

So now back at the Terminal prompt, a few simple instructions

perl Build.PL
./Build
sudo ./Build install

That put biblatex-biber onto the path for all users: everything then worked correctly.

Ubuntu 9.10

Once again, Perl is installed as standard in Linux distributions: I’m using Ubuntu as a representative system. Before starting cpan, there is an additional step, which is to install an extra Ubuntu package. So at the Terminal, you need to do

sudo apt-get install libxml2-dev

This is needed as otherwise you get some very odd errors in a bit. Now, essentially the same recipe works as for the Mac. First run cpan running and update and install YAML. Then there is a long list of items to install

install Data::Dump List::AllUtils Readonly Text::BibTeX Readonly::XS XML::Writer XML::LibXML File::Slurp

which can again be done one at a time, for the more cautious.

After exiting cpan, the same three lines at the Terminal should work as in the Mac section.

perl Build.PL
./Build
sudo ./Build install

Windows (XP, Vista and 7)

To date, my attempts to build biblatex-biber on Windows (using Strawberry Perl) have failed as I can’t get the Perl module Text::BibTeX to install. This is supposed to be optional, but without it biblatex-biber does not seem to work, although I do get it to build. Luckily, there is a self-contained binary for Windows available from the project site. This includes its own Perl system, so there is no need to get Perl set up before trying it. Everything seems to work for me with this version. Any ideas on what is necessary would be helpful!

Written by Joseph Wright

January 23rd, 2010 at 8:24 pm

Posted in LaTeX, biblatex

Tagged with , ,

achemso: Cross-referencing to floats

without comments

I’ve had a a few questions about the achemso bundle concerning creating references such as “Figures 1 to 3” automatically. The problem has been that I’ve been using the varioref package to turn \ref{some-fig} in “Figure 1” automatically, rather than having to put Figure~\ref{some-fig}. Unfortunately, varioref does not handle multiple references in an automated fashion.

For version 3.4 of achemso (which I’ve just sent to CTAN), I’ve switched to the cleveref package. This means that you can now write something like \ref{fig-1,fig-2,fig-3} and get “Figures 1 to 3” without further effort. I hope that this makes life much easier for users, although it does mean that there is another package required to use achemso. I think that this is the right balance: I’m sure users will let me know if I’ve got it wrong.

Written by Joseph Wright

January 16th, 2010 at 9:55 am

Posted in LaTeX, achemso

Tagged with ,

Chemistry journals: publishers support of LaTeX

with 6 comments

As the author of the achemso bundle (for supporting submissions to the American Chemical Society), I get a few queries about the support various publishers provide for LaTeX. Unlike more physics-focussed journals, the chemistry journals never typeset directly from authors LaTeX sources.  As a result, the acceptance of LaTeX material from authors is rather less popular, and tends to be patchy. So I thought I’d summarise things as I currently understand them.

American Chemical Society (ACS)

As I said above, I’ve written the achemso bundle specifically for submissions to the ACS. However, while the central office are happy to host a copy on their website and so on, the ACS don’t officially support the bundle. That means, in practice, that some journals are happier with LaTeX submissions than others. Each journal has its own office, and so I hear different things from people submitting to different journals. It also means that I have to pick up the requirements of each office based on feedback via authors, rather than getting any formalised instructions. There are mistakes in the achemso bundle, and there are also requirements that I don’t know about. So feedback is always useful (good or bad).

Royal Society of Chemistry (RSC)

The RSC have rather less information about LaTeX on their website than the ACS. They do mention TeX, but only very briefly. I’ve written some BibTeX styles, and a very basic article template, which are available in the rsc bundle. I’ve had a bit of feedback on these, and I hope that they at least provide a starting point for writing a submission to the RSC in LaTeX. More generally, I think the best advice is to check with the editorial office for the relevant journal before writing anything, and to stick to the basic LaTeX article class when you do.

Wiley

As with the RSC, Wiley don’t have a lot of LaTeX information. What they do say is that they only accept PDF submissions: you can’t send your source. They also say to stick to the plain article class, and basically to keep things simple.

Elsevier

Elsevier have recently had a new class written for journal submissions, elsarticle. From what I can make out on their site, you can use this for most of their journals, which should include the chemistry ones. As this has actually been written for them to order, I imagine that Elsevier is the best place to be sending LaTeX submissions to. Hopefully other publishers will see that they have made life easier for their authors and will take note.

Written by Joseph Wright

January 5th, 2010 at 8:08 pm

Posted in LaTeX

Tagged with

siunitx performance (again)

without comments

My previous post mentioned some efforts to improve the performance of the siunitx parser. I’ve now committed an entirely new version of the parsing code to the repository. I’ve also done my best to speed up the rest of the package. The speed you see very much depends on the type of input involved. With my test file, I got a time of roughly 3 minutes using version 1 of siunitx, about 2 minutes before improving version 2, and about 1.5 minutes after. For comparison, doing no processing at all take the time down below 10 seconds for the same file (roughly 700 pages of repeated input). For the interested reader, an siunitx snapshot TDS-style zip is available.

One thing that I find interesting in all of this is that even before optimising the code, version 2 still worked faster than version 1, even though it does more things. A lot of that is because the pre-built looping material in expl3 does a much better job than my own attempts in version 1 of siunitx. Of course, good programmers will always use fast loops, but for the rest of us I think this shows how a sensible tool-kit can bring benefits “behind the scenes”.

Written by Joseph Wright

January 4th, 2010 at 7:48 pm

Posted in LaTeX, siunitx

Tagged with , ,

siunitx performance

without comments

I had an e-mail today about using siunitx when there are a lot of calls to the package. As you might expect, things can get a bit slow, and the person who contacted me felt that things get rather too slow. There are differences between the current release version of siunitx and the development code (version 2), and I’ve also added a few features to help speed things up where appropriate using version 2. So I thought I’d put a bit of information on the comparison in the public domain.

First, a baseline is not to use siunitx at all, and to simply test everything by hand. For that, I tried the simple test file:

\documentclass{article}
\usepackage{siunitx,xparse}
\ExplSyntaxOn
\DeclareDocumentCommand \repeated { m m }{
  \prg_replicate:nn {#1} {#2}
}
\ExplSyntaxOff
\begin{document}

\repeated{10000}{$1.23\,\text{m}$ }

\end{document}

This repeats the same text 10 000 times: boring but handy for testing. Using the command-line time program, I get an overall time of 1.714 s for this.

A very slight change of the file lets me test with siunitx version 1:

\documentclass{article}
\usepackage{siunitx,xparse}
\ExplSyntaxOn
\DeclareDocumentCommand \repeated { m m }{
  \prg_replicate:nn {#1} {#2}
}
\ExplSyntaxOff
\begin{document}

\repeated{10000}{\SI{1.23}{\metre} }

\end{document}

With the latest release version of siunitx (v1.3g), I get a time of 80.878 s for this on the same system.

In siunitx version 2, I’ve recoded all of the loops and parsing code, and so things are faster using the standard settings: 58.944 s. With the very latest code (SVN 243), I’ve included two options to make things move faster: parse-numbers and parse-units. Of course, these do mean that you get less of the power of siunitx. But for many people they might be useful. Turning both parsing systems off, the time needed for the test file drops to 14.975 s (just turning off the number parser gives a time of 18.803 s).

I may take another look at trying to improve the performance of the number parser. The problem is at least in part that making the code faster will either mean making some of it less powerful or, more likely, a lot harder to read and maintain. I hope that for most people, most of the time, the performance is acceptable. Of course, at some point I’ll try to do some Lua-based code for the parsers, at least. But that won’t help for most users now.

Ultimately, there is a limit to how fast things can work. Whether the performance hit of using siunitx is worthwhile is something is down to users. I think it’s worth it, as the better logic in the mark-up more than makes up for the extra time required. But then I would say that!

Written by Joseph Wright

December 28th, 2009 at 10:43 pm

Posted in LaTeX, siunitx

Tagged with ,

siunitx: Getting the micro symbol right

with one comment

I get a few e-mails about siunitx and the micro symbol. People tend to be surprised that the symbol ‘sticks’ to a look very much like Computer Modern. The reason is that picking a proper upright (not italic) μ is not so easy in TeX.You don’t get one in Computer Modern, so siunitx takes one from the TS1 (text support) set in the absence of a better plan. I’ve set up some auto-detection for a few obvious alternatives (such as the upgreek package), but that doesn’t really work for XeTeX users.

XeTeX users are likely to load system fonts, and I’d hope be using UTF-8 input. That makes it hard to auto-detect what they are doing, but should make life easier for them to get things right. A lot of more comprehensive fonts include Greek letters in the main font, so getting the μ right is simple:

\sisetup{
  mathsmu = \text{μ},
  textmu  = μ
}

or for people testing version 2 of siunitx:

\sisetup{
  maths-micro = \text{μ},
  text-micro  = μ
}

There may be a bit of testing required: this will not work if, for example, you are using the Latin Modern font.

Written by Joseph Wright

December 22nd, 2009 at 9:12 pm

Posted in LaTeX, siunitx

Tagged with , ,