2

Well, the title pretty much says it all, I'm looking for a way to tell if a string has any letters in it or if it's made up of just numbers.


I used biblatex as a tag here because of my question's purpose:

I'm trying to write my own custom style and the volume field automatically adds "vol." before the volume number. But the norms I have to follow make a few exceptions about that, and sometimes (and there isn't really a pattern to follow, these are just random exceptions) the "volume" field should be printed differently (as "year 4", for instance, instead of "vol. 4"). As it is the user can't fill in "year 4", though, or it'll print "vol. year 4".

The same goes for the edition field. I add "ed." to it, so it prints something like "3rd ed.". But I want my users to be able to fill in something like "3rd ed. revised and augmented"… and as it is, if they do that, the bibliography will print "3rd ed. revised and augmented ed.".

So what I'm thinking is I could check if the volume and edition fields contain only numbers, and if so I can add "vol." and "ed.". Otherwise I won't add anything because I'll assume the user did it himself. Is there any other way to do something like that?

Thanks in advance,

Daniel

  • What about vol. 5A3 then? (I think I have seen such) – yo' May 2 '16 at 6:05
  • @yo' What about it? Then the user could just type that whole thing, "vol. 5A3". – dbmrq May 2 '16 at 6:43
5

biblatex has a host of commands for that.

There are (see pp. 199-200 of the biblatex doc)

  • \ifinteger to check if the given argument is a positive integer
  • \ifnumeral to check if the argument is a number given either in the Roman or Arabic system
  • \ifnumerals for ranges of (Roman or Arabic) numerals
  • \ifpages for detection of pages

Those commands have a version that can directly check a field: \iffieldint, \iffieldnum, \iffieldnums, \iffieldpages.

The numeral and pages checks can be configured to treat certain constructs as numerals or pages, see pp. 210-211. You might be interested in \DeclareNumChars.


The standard styles use \ifinteger for the edition field

\DeclareFieldFormat{edition}{%
  \ifinteger{#1}
    {\mkbibordedition{#1}~\bibstring{edition}}
    {#1\isdot}}
  • Awesome, thanks for the 100th time this week. :) – dbmrq May 2 '16 at 6:41

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.