1

Attempting to write a command that will produce a line of circles with the first n filled. Desired functionality would be \IBmark{l}{m} where l is the length of the line and m is the number of filled circles.

Using LaTeX in overleaf

\newcommand{\IBmark}[2]{\pgfmathparse{#1-#2}\textbf{\multido{}{#2}{\CIRCLE}\multido{}{\pgfmathresult}{\Circle}}}

Is my best attempt to get this working using the tikz package however it returns this

⚫⚫⚫.0OO

For l = 5, and m = 3 rather than the desired

⚫⚫⚫OO

Attempts to use the rounding allowed by the pgf print command returned worse results. I can not seem to find a way to remove the error.

1
  • Try adding int, as in \pgfmathparse{int(#1-#2)} – Steven B. Segletes Apr 24 '20 at 10:27
1

You need to add int(...) to the \pgfmathparse calculation.

Also, in this implementation, the use of \textbf is irrelevant and is thus removed.

\documentclass{article}
\usepackage{txfonts}
\usepackage{pstricks-add}
\def\CIRCLE{$\medbullet$}
\def\Circle{$\medcirc$}
\newcommand{\IBmark}[2]{\pgfmathparse{int(#1-#2)}%
  \multido{}{#2}{\CIRCLE}\multido{}{\pgfmathresult}{\Circle}}
\begin{document}
\IBmark{5}{3}
\end{document}

enter image description here

3

Welcome! From the pictures I take that you might want something like this:

\documentclass{article}
\usepackage{tikz}
\newcommand{\IBmark}[2]{\begin{tikzpicture}[baseline={(X.base)},
cfill/.code={\unless\ifnum\X>#2
\tikzset{fill}
\fi}]
\path (1,-0.25ex) node (X) {\vphantom{X}}foreach \X in {1,...,#1}
{(\X*1.2em,0) node[circle,draw,minimum size=1em,cfill] {}};
\end{tikzpicture}}
\begin{document}
Hello \IBmark{5}{3}.
\end{document}

enter image description here

You can adjust the vertical position of the phantom node to get any alignment you want. In principle one does not need TikZ for that but it is certainly very easy to get this done with TikZ.

1

If we are using OpTeX then we can do:

\def\ibmark#1#2{\fornum 1..#1\do{\ifnum##1>#2$\circ$\else$\bullet$\fi}}
\ibmark{5}{3}
\bye

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.