I need to perform a test on the current font shape. More specifically, I need to detect whether the current font shape is italic or slanted.

Joseph Wright already provided a solution in his answer to Detect which text "mode" (normal, italic, bold, etc.) is currently in use?. For instance, if you define




will be true if the current font shape is italics.

However, as I'm trying to avoid code duplication as much as possible, I'm wondering whether there really is a need to define macros that expands to it (for italics), sl (for slanted), etc. I suspect there may already exist such macros, perhaps defined in the LaTeX kernel. Is that the case? If so, what are those macros called?


I suppose that you are looking for \bfdefault, \itdefault and stuff:

$ for x in bf it sl md up rm sf tt; do texdef -t latex ${x}default; done;

\long macro:->bx

\long macro:->it

\long macro:->sl

\long macro:->m

\long macro:->n

\long macro:->cmr

\long macro:->cmss

\long macro:->cmtt

Be careful since they are all \long.

  • That looks like what I'm looking for, but \slshape\ifx\f@shape\sldefault fails. I guess it's got to do with this \sldefault being long whereas \f@shape isn't... – jub0bs Mar 6 '14 at 13:12
  • According to this comment by Joseph, I'm on the right track. I'll figure something out. I'll accept your answer. Thanks. – jub0bs Mar 6 '14 at 13:28
  • These are right only if not changed: you can't be sure that they'll always expand in the desired way – Joseph Wright Mar 6 '14 at 13:57
  • @JosephWright Depends what's "right". They'll show if the current setting was accomplished by \slshape. – yo' Mar 6 '14 at 14:31
  • @tohecz Yes, but not if the current setting has absolute code sl, for example: depends what you want to test for – Joseph Wright Mar 6 '14 at 14:34

Can easily be extended to what you need

\curr@fontshape --> \expandafter\getFSh\curr@fontshape\@nil

\curr@fontshape --> \expandafter\getFSh\curr@fontshape\@nil

\curr@fontshape --> \expandafter\getFSe\curr@fontshape\@nil\relax, 

enter image description here

  • Not a direct answer to my question, but still useful. Thanks. – jub0bs Mar 6 '14 at 13:08
  • @Jubobs See nfssext-cfr and nfssext for examples using this sort of approach. – cfr Mar 7 '14 at 2:24

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.