7

I would like to distinguish two cases when using the unit \byte:

  1. if used without prefix it should be written as "Byte" in the text
  2. if used with prefix, e.g. \kilo\byte, I would like to get "kB"

Do I need to declare different units for use with/without prefix or can this be handled by the package?

  • Just a friendly reminder, we usually don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. (See Welcome to TeX.SX! for more awesome info.) – Sean Allred Jun 24 '13 at 19:45
  • If it's not mentioned in the manual (I haven't read it), then it isn't so provided. The best way to find out is to skim through it (Ctrl/Cmd+F is your friend ;)). I don't think it is, but this behaviour can probably be tacked on. – Sean Allred Jun 24 '13 at 19:46
  • 4
    Units are symbols, not abbreviations. If you don't want the symbol, spell out the name: “10~bytes”. – egreg Jun 24 '13 at 20:19
3
\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[binary-units]{siunitx}
\DeclareSIUnit\mybyte{Byte}

\begin{document}

One thousand bytes is \SI{1}{\kibi\byte}

One byte is \SI{1}{\mybyte}

\end{document}

enter image description here

Suggestion:

  • Use byte instead of Byte when the unit is not abbreviated.
1

The second case you mention:

if used with prefix, e.g. \kilo\byte, I would like to get "kB"

Is the default behavior with siunitx, so you shouldn't worry about it. E.g.

\SI{1}{\kilo\byte}

For the first one:

if used without prefix it should be written as "Byte" in the text

I would suggest you define your own macro named \mybyte at your preamble. E.g.

\newcommand{mybyte}{Byte}

So when you want to have the prefix, just type:

One thousand bytes is \SI{1}{\kilo\byte}

or alternatively:

 One byte is \SI{1}{\mybyte}

Code example:

\documentclass{article}

\usepackage{siunitx}

\newcommand{\mybyte}{Byte}

\begin{document}

One thousand bytes is \SI{1}{\kilo\byte}

One byte is \SI{1}{\mybyte}

\end{document}

Result:

enter image description here

  • Wouldn't it be better to define \mybyte as a proper unit using \declareSIUnit, instead of using \newcommand? – Jake Jun 24 '13 at 20:18
  • @Jake Could be, but I don't know if when using \SI{1}{\kilo\byte} would work – Mario S. E. Jun 24 '13 at 20:20
  • 2
    Since Byte is not an abbreviation, the space between 1 and Byte should be a normal text space, not a thin space. – daleif Jun 25 '13 at 9:02

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.