Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have some math formulas where I need bold roman style for some math expressions. Since they appear quite often, I need a macro for them. The obvious way is to write \newcommand{\foo}[1]{\mathbf{#1}}, which works in principle. However, it falls apart when the command argument contains a superscript, and there is a subscript added outside the command, like so: \foo{x^k}_t which results in

x^k_t with wrong spacing

where the t subscript is too far away, presumably because it's outside an mbox. Using the bm package and defining \newcommand{\foo}[1]{\bm{#1}}, I get the correct spacing as I want it:

x^k_t with right spacing but wrong font

But now I'm back to the wrong font as it's no longer in Roman style. And all approaches I've tried to combine \bm and switching to a Roman style show up fail in one way or another. I can't seem to find a solution that will look like the second case, but use a Roman font like in the first case. Any ideas on how I could solve this? Thanks in advance!

share|improve this question
    
Must the subscript and superscript also be in bold roman, or in bold italic, or in ordinary math style? –  Bernard Mar 15 at 19:27
    
Good point, I guess I should have clarified some more. Whatever is inside the \foo{} should be in bold roman, but whatever is outside it, should be in ordinary math style. But as opposed to my first example (which has the fonts all correct), it should be right next to the x, rather than outside the mbox containing the x^k. –  mindriot Mar 16 at 1:26

3 Answers 3

up vote 4 down vote accepted

enter image description here

You can get from the markup you want to the markup barabra correctly said that you need:

\documentclass{article}
\usepackage{bm}
\def\foo#1{\xfoo#1\relax^\relax\valign}
\def\xfoo#1^#2\relax#3\valign{%
\mathbf{#1}\ifx\valign#2\valign\else^{\mathbf{#2}}\fi}
\begin{document}
$\foo{x}$, $\foo{x}_t$

$\foo{x^k}$, $\foo{x^k}_t$
\end{document}
share|improve this answer
    
Perfect, that did it. Thanks! –  mindriot Mar 16 at 9:41

you can use \mathbf to get the upright letters -- but you have to enter them separately for base and scripts:

$\mathbf{x}^{\mathbf{k}}_t$

output of example code

share|improve this answer
    
Thanks for your input! Yes, I could do that. But the thing is that in my case the x^k is inside the macro (e.g. \foo{x^k}_t), and in my case I can't separate the \mathbf{} command like that. I.e., I basically want to create a command \foo{x} which behaves exactly like \bm{x}, except it uses bold upright/roman characters instead of bold standard characters. I could modify my commands/macros to use multiple parameters to follow your suggestion, but it would be an awful mess of macros... –  mindriot Mar 16 at 1:20

You could modify the definition of \foo to instruct \bm to operate on \mathrm{#1} instead of "just" #1. (By the way, I'm assuming that since the main symbol and the superscript term should be in upright bold, the same goes for the subscript term. Please advise if this assumption is invalid.)

enter image description here

\documentclass{article}
\usepackage{bm}
\newcommand{\foo}[1]{\bm{\mathrm{#1}}}
\begin{document}
$\foo{x^k}$, $\foo{x^k_t}$
\end{document}
share|improve this answer
    
Thanks for your input! The difference in your example is, you have the "_t" inside the command parameter, where I wanted \foo{x^k}_t. I.e., t should not be set in bold upright, but in normal style. –  mindriot Mar 16 at 1:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.