2

I'm trying to create a large blue star.

I don't want to type {\Large \textcolor{blue}{$\star$}} everywhere, so I used

 \DeclareMathOperator{\Star}{{\Large \textcolor{blue}{$\star$} \thinspace }}

But when I use \Star, I receive missing $ inserted, missing } inserted, ... everywhere.

What gives?

Heiko Oberdiek
  • 271,626
Fraïssé
  • 3,139

4 Answers4

4

You get an error as when the command is used in math mode, the $ will end math, however you also get a separate warning as you can not use size commands such as \Large in math mode. You could use

 \DeclareMathOperator{\Star}{{\text{\Large \textcolor{blue}{$\star$} \thinspace }}}

Although the \Large would prevent the operator getting smaller in subscripts.

It would be better to use a font with a larger star, rather than using a size comand here, depending on the actual use case.

David Carlisle
  • 757,742
3

Commands such as \Large cannot be used in math mode. Moreover the second argument of \DeclareMathOperator will be used in math mode, so $ inside it is not allowed.

I guess you want to use the big blue star like the summation sign. Then https://tex.stackexchange.com/a/23436/4427 can come to rescue.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{xcolor}

\makeatletter \DeclareRobustCommand\bigop[1]{% \mathop{\vphantom{\sum}\mathpalette\bigop@{#1}}\slimits@ } \newcommand{\bigop@}[2]{% \vcenter{% \sbox\z@{$#1\sum$}% \hbox{\resizebox{\ifx#1\displaystyle.9\fi\dimexpr\ht\z@+\dp\z@}{!}{$\m@th#2$}}% }% } \makeatother

\newcommand{\Star}{\DOTSB\bigop{\mathcolor{blue!90}{\star}}}

\begin{document}

[ \Star_{i=1}^n f(i) = \sum_{i=1}^n g(i) ] \begin{center}% just for a smaller picture $\Star_{i=1}^n = \sum_{i=1}^n g(i)$ \[2ex] $ X_{\Star_{i=1}^n f(i)} = X_{\sum_{i=1}^n g(i)}$ \end{center}

\end{document}

You see that the symbol properly changes size like \sum.

enter image description here

egreg
  • 1,121,712
3

You can use the scalerel package to make the blue star scale to the size of \sum:

enter image description here

\documentclass{article}

\usepackage{amsmath,scalerel,xcolor}

\DeclareMathOperator{\Star}{\scalerel{\textcolor{blue}\star}{\sum}}

\begin{document}

Display: $\displaystyle{\Star_{n=1}^{\infty} a_n}$ Inline: $\Star_{n=1}^{\infty} a_n$. Scripts: $A_{\Star_{\Star}}$

\end{document}

Sandy G
  • 42,558
2

If \Star is supposed to be a math operator, I believe the symbol should be centered vertically on the math axis rather than be placed smack dab on the baseline. This may be achieved via a \vcenter directive. And, to enlarge the star symbol, I suggest you load the graphicx package and employ its \scalebox macro. In the following example, the scaling factor is set to 3; you're obviously free to use a different value.

enter image description here

\documentclass{article}
\usepackage{amsmath}  % for \DeclareMathOperator macro
\usepackage{graphicx} % for \scalebox macro
\usepackage{xcolor}   % for \mathcolor macro
\DeclareMathOperator{\Star}{\vcenter{\hbox{%
    \scalebox{3}{$\mathcolor{blue}{\star}$}}}}

\begin{document} $\star-\Star-\star$ \end{document}

Mico
  • 506,678