0

I have used the \def command for several long scientific terms so that I can have an easy shorthand reference and do not have to keep typing them out every time e.g. \carb for $\delta$$^{13}$C (full code \def\carb{$\delta$$^{13}$C }). However if I do not include the final space after the C the output runs into the next word. This is problematic if I use the definition before full stops or ) because it adds an extra space, for example (δ13C ) or [δ13C .].

I tried the xspace package which did work for punctuation problems, but it doesn't add a space after words which I would like in italics. I added {} in my document and this did solve the problem, but I was wondering if there was an easier way? An example of a define command I have which has this problem is: \def\geog{\textit{geography\xspace}}

Thank you!

  • 1
    Welcome! Please expand your code to an example which people can compile and which demonstrates the problem. However, {} is the standard approach and xspace is know to be not without problems. You would, however, be wise to avoid \def and use \newcommand if you are using LaTeX. Also, why do you have $$? This just ends maths mode and immediately begins it again. – cfr Sep 13 '17 at 13:55
  • If you really want to use \xspace, it should be the very last item in the body of the definition. Don't use \def, but \newcommand; once you do \def\box{box} you'll know why. – egreg Sep 13 '17 at 13:57
  • 1
    that is simply user error and should be \def\geog{\textit{geography}\xspace} although personally I wouldn't use xspace (even though I wrote it) – David Carlisle Sep 13 '17 at 14:02
  • Thanks for pointing out my mistake, once I put \xspace in the right place it worked! I'll also change the code to \newcommand instead. Thanks so much for your help. – dragoness24 Sep 13 '17 at 14:04
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Sep 25 '17 at 13:30
3

I wouldn't use a tons of command like \carb. This method is at the end imho quite messy and quite often good command names are already take by other packages. I would use one command, e.g. \sh (for shorthand) with an argument. Beside solving the problem with the space it also allows you to use numbers and punctuations. A simple method is this but you can also use glossaries or acro.

\documentclass{article}
\makeatletter
\@namedef{myshorthand@carb}{$\delta$$^{13}$C}
\@namedef{myshorthand@carb-12}{$\delta$$^{12}$C}
\@namedef{myshorthand@carb-n}{$\delta$$^{n}$C}

\newcommand\sh[1]{\csname myshorthand@#1\endcsname}
\makeatother

\begin{document}
\sh{carb}, \sh{carb} blblb 

\sh{carb-12}, \sh{carb-n}

\end{document}

enter image description here

0

I wouldn't use \xspace but if you do use it the syntax is

\newcommand\geog{\textit{geography}\xspace}
  • 1
    I believe that the exponent refers to the subsequent C. – egreg Sep 13 '17 at 14:07
  • @egreg I deleted that bit then, but the markup's not great in any case:-) – David Carlisle Sep 13 '17 at 14:21

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.