4

Is there any possible way to count by the number of a symbol ? For instant, if I want to print 4 versions of a letter, I assigned \arabic{#1} numbers which shows:

1 2 3 4

What I want is to show like this:

* ** *** **** Or; different symbols instead of for each number. for example:

 * for 1
# for 2 

and etc.

I'm preparing different versions of exam and I want to show version number by symbol instead of number. Thanks in advance.

UPDATE: Even though I've got good responses from experts, However, I'm still unable to do what I exactly need. I guess I couldn't elaborate my question well, that's why I've decided to provide a minimal code. This is my code:

\documentclass[twoside]{article}
\usepackage[english]{babel}
\usepackage{comment}
% set fonts
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{microtype}
\usepackage{etoolbox}
\newcommand{\comm}[1]{}
\ifdef{\myoutput}{}{\def\myoutput{exam}}
\ifdef{\myversion}{}{\def\myversion{2}}

% mcexams options.
\usepackage[output=\myoutput
           ,numberofversions=5
           ,version=\myversion
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=true
           ]{mcexam}

\usepackage[margin=0.95in]{geometry}
% Packages used for special things
\usepackage{framed,booktabs} 


% Set headers and footers
\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lhead{Name:\hrulefill{}\quad Student ID:\hrulefill{}}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}


\begin{document}
% Exam preamble stuff - this will be printed on every version
\begin{center}
  \bfseries\Huge exam title \\
  \LARGE 

\end{center}

% Show which version is being printed (Concept, Answers, etc.)
\begin{center}\bfseries\Huge\MakeUppercase{\mctheversion}\end{center}

% This only shows on the "Exam" form that students see. So put instructions, etc. here.
\mcifoutput{exam}{
\large\bigskip

\noindent Name: \hrulefill{}\hrulefill{}\hrulefill{}\quad{}Student ID\#: \hrulefill\hrulefill{} \\[.75\baselineskip]



On your scantron, use either a pencil or pen:

} % end if exam



\end{document}

I'll be so grateful if anyone can give me the exact solution to solve this specific issue. I tried to define newcounter or chnaging \mctheversion value but still I get numbers instead of symbols in version. Please look at image below: enter image description here

4

Without any packages, just using standard LaTeX code and a 'primitive' \loop.

\documentclass{article}

\newcounter{mycntr}

\makeatletter
\newcommand{\lettersymbols}[1]{%
  \begingroup
  \setcounter{mycntr}{0}
  \loop\unless\ifnum\value{mycntr}=#1
  \mysymbol%
  \addtocounter{mycntr}{1}%
  \repeat
  \endgroup
}
\makeatother

\newcommand{\mysymbol}{\textasteriskcentered}

\begin{document}
\setcounter{section}{5}

\renewcommand{\thesection}{\lettersymbols{\number\value{section}}}

\thesection

\end{document}

Code from OP

The \mctheversion macro is responsible for the output of the version, so just change that accordingly, with \lettersymbols or \repeatedsymbols. Please note, that \MakeUppercase may fail.

\documentclass[twoside]{article}
\usepackage[english]{babel}
\usepackage{comment}
% set fonts
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{microtype}
\usepackage{etoolbox}
\newcommand{\comm}[1]{}
\ifdef{\myoutput}{}{\def\myoutput{exam}}
\ifdef{\myversion}{}{\def\myversion{2}}


\newcommand{\mysymbol}{\textasteriskcentered}


\newcount\mycntr

\newcommand{\repeatedsymbols}[1]{%
  \begingroup
  \mycntr=0
  \loop\unless\ifnum\mycntr=#1%
  \mysymbol%
  \advance\mycntr by 1
  \repeat
  \endgroup
}



\newcommand{\lettersymbols}[1]{%
  \ifcase#1
  \or
  \textasteriskcentered
  \or
  \textdollar
  \or
  \textdagger
  \or
  \textsection
  \or
  \textsterling
  \fi
}


% mcexams options.
\usepackage[output=\myoutput
           ,numberofversions=5
           ,version=\myversion,
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=true
           ]{mcexam}

\usepackage[margin=0.95in]{geometry}
% Packages used for special things
\usepackage{framed,booktabs} 


% Set headers and footers
\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lhead{Name:\hrulefill{}\quad Student ID:\hrulefill{}}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}


\AtBeginDocument{%
  \renewcommand{\mctheversion}{\lettersymbols{\value{mcversion}}}
%  \renewcommand{\mctheversion}{\repeatedsymbols{\value{mcversion}}}
}


\begin{document}

% Exam preamble stuff - this will be printed on every version
\begin{center}
  \bfseries\Huge exam title \\
  \LARGE 

\end{center}

% Show which version is being printed (Concept, Answers, etc.)
\begin{center}\bfseries\Huge\mctheversion\end{center}

% This only shows on the "Exam" form that students see. So put instructions, etc. here.
\mcifoutput{exam}{
\large\bigskip

\noindent Name: \hrulefill{}\hrulefill{}\hrulefill{}\quad{}Student ID\#: \hrulefill\hrulefill{} \\[.75\baselineskip]



On your scantron, use either a pencil or pen:

} % end if exam



\end{document}
  • Thank for suggestions. However, I still couldn't mange how to solve it. Is there any way to send the original file here so that you can look at it in case you have spare time? – Majid Dec 24 '18 at 18:06
  • @Majid I will update at a later point of time – user31729 Dec 25 '18 at 16:47
  • I have updated my question (I've added a minimal code with image of what I want). Would you please let me know how to solve it . Thanks – Majid Dec 26 '18 at 8:04
  • @Majid: I can't compile your example – user31729 Dec 26 '18 at 9:16
  • I edited it, I checked it compiled in ovearleaf correctly. Would you please check it again. Thanks – Majid Dec 26 '18 at 10:51
4

You can easily do it with xparse:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\numsym}{m}
 {
  \int_compare:nTF { \use:c { c@#1 } > \tl_count:N \c_majid_numsym_tl }
   {
    \use:c { @ctrerr }
   }
   {
    \tl_item:Nn \c_majid_numsym_tl { \use:c { c@#1 } }
   }
 }

\tl_const:Nn \c_majid_numsym_tl
 {% add to the list using the same format {<command>}
  {*}{\#}{@}{!}{?}
 }
\ExplSyntaxOff

\newcounter{test}
\renewcommand{\thetest}{\numsym{test}}

\begin{document}

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\end{document}

enter image description here

Repeating a symbol is even easier:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\repsym}{mm}
 {
  \prg_replicate:nn { \use:c { c@#2 } } { #1 }
 }
\ExplSyntaxOff

\newcounter{test}
\renewcommand{\thetest}{\repsym{*}{test}}

\begin{document}

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\end{document}

enter image description here

2

I do not know if this already exists but it is easy to build something of this sort. Of course, you need to make the list of symbols longer if you want to go to higher values.

\documentclass{article}
\usepackage{pgffor}
\newcommand{\nbullets}[1]{%
\foreach \X in {1,...,#1}
{\textbullet}}
\def\lstsyms{{"","*","\#","@","!","?"}}
\newcommand{\numsymbol}[1]{%
\pgfmathparse{\lstsyms[#1]}%
\pgfmathresult
}

\begin{document}
3:\nbullets{3}, 7:\nbullets{7}

\renewcommand{\labelenumi}{\nbullets{\value{enumi}}}
\begin{enumerate}
 \item first
 \item second
 \item third
 \item last 
\end{enumerate}

1:\numsymbol{1}, 2:\numsymbol{2}, 3:\numsymbol{3}
\end{document}

enter image description here

  • Thank you for your prompt reply. However, I couldn't use the code. Let me explain it more. I'm using mcexam package which generate different versions of exam. There is a command in mcexam.sty which defines the version and shows it on exam, key, answer and concept. However, I want to replace the version number with a symbol. So, every version is hsown by a symbol instead of a number. It means I may need a counter to count by a set of symbols instead of numbers !! Hope I could elaborate my concern ! – Majid Dec 24 '18 at 17:37
  • @Majid I guess you might want to add a real life application in form of an MWE to your question. (And of course you can use the above with a counter. Just add \newcounter{mycount}\setcounter{mycount}{2}\numsymbol{\value{mycount}} to my code. It works the same way with existing counters, as the enumerate example already shows.) – user121799 Dec 24 '18 at 17:41

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.