3

I have a linked question that I previously found on here, but I cannot make any comment yet to post. The link being: Good way to make \textcircled numbers?

My question was how could we use this command more then once in our TeX file in different parts of our file without generating an error.

Example Code:

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{1} \circled{2} \circled{3} end.
\end{document}

The error message is this:

! LaTeX Error: Command \circled already defined.
               Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

1.222 ...circle,draw,inner sep=2pt] (char) {#1};}}

When removing the \newcommand* it shows this next error message:

! You can't use 'macro parameter character #' in restricted horizontal mode.
<argument> ...ircle,draw,inner sep=2pt] (char {##
                                                 1}

Can someone help out please. Thank You so much.

night owl
  • 7,593
  • Are you getting those error messages with the exact code you posted? I ask you because that code compiles OK in my system. – Gonzalo Medina Apr 08 '11 at 17:49
  • Like @Gonzalo already said: The above example code compiles fine. You seem to define \circled multiple times, instead of using it. Make sure that you only have one \newcommand and that it isn't inside a macro you use. – Martin Scharrer Apr 08 '11 at 17:53
  • Also: welcome to TeX.SX! A tip: you can use backticks ``` to format inline code or package names, like I did in my edit. We also prefer to not have any opening or closing lines. Thanks. – Martin Scharrer Apr 08 '11 at 17:59
  • Yea, i used that entire code in two separate locations with the new command in each of them in the TeX file. I just want to put the circle somewhere different in the file without saying it is used multiple times. Thanks, for the warm welcome. – night owl Apr 08 '11 at 18:01
  • @nightowl: It's ok to have the \newcommand* in several different files, but it should only be once per file. – Martin Scharrer Apr 08 '11 at 18:07
  • 6
    @night owl. I quote: "I used that entire code in two separate locations with the new command in each of them in the teX file." That is definitely not what you should do (unless I misunderstand what you mean). You just need one single definition in the preamble. You also just need one preamble. Does the code snipplet you quoted by itself compile fine for you? If so, search your TeX file for duplicate definitions of \circled. – Willie Wong Apr 08 '11 at 18:15
  • @Martin: I was using only one file my the work, not separate projects. How could you re-enumerate correctly without using the \newcommand or \circled but still get the same results as coding it in for the first time. – night owl Apr 08 '11 at 19:39
  • @nightowl: I'm not sure what you try to achieve. Anyway, you only need and must have the \newcommand*\circled once in the preamble and then you can use it multiple times, like in your example which works fine. If you want automatic numbering, so you don't have to add the number in \circled manually, then please edit your question and ask explicitly for it. – Martin Scharrer Apr 08 '11 at 19:46
  • @Martin: Okay for scenario: When you run the file you get the numbers created within circles. What I was trying to do for instance is having saying #1 circled to label one paragraph. Then #2 circled label another paragraph, .... and so on. Or e.g. having an order list say. (All numbers are circled) [1 2 3 4]^{T} in say the beginning of your TeX file and then have again. [1 2 3 4]^{T} somewhere at the bottom of your file, without having any issues. What my question was, for the ordered list towards the bottom of the file. How would i declare that without using \newcommand and \circle again? – night owl Apr 08 '11 at 20:14
  • @nightowl: Please update your question and give an example of what you want to do exactly. Add some code which doesn't work so that we can tell you what's wrong. – Martin Scharrer Apr 08 '11 at 20:25
  • @Martin: Sorry I would like to but I have to have 10 reps before I can post up any pictures to here. When I do, I will update the question. – night owl Apr 08 '11 at 20:49
  • @nightowl: Just upload it to http://imgur.com/ and post the link instead. I can include the images for you. I don't have any votes left for today, so I can't upvote your question. – Martin Scharrer Apr 08 '11 at 20:51
  • @Martin: Thanks for that website: Here is the corresponding direct link:

    http://i.imgur.com/NxEdq.jpg

    – night owl Apr 08 '11 at 21:06
  • @nightowl: Just make the edits like in the image and remove the ! in front of the image code to turn it into a link. I can turn it back to an image for you. – Martin Scharrer Apr 08 '11 at 21:09

1 Answers1

5

As is mentioned in the comments, your example code compiles fine, but you mustn't use the \newcommand*\circled more than once. If you want more circled numbers, just use \circled{n} for each instance of a circled n.

My guess is that you did the following: You tried some code like

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{1} \circled{2} \circled{3} end.
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
Numbers aligned with the text:  \circled{1} \circled{2} \circled{3} end.
\end{document}

and got ! LaTeX Error: Command \circled already defined. This is expected behaviour; you should define \circled only once in the preamble. Then you tried removing the second \newcommand*, but you only removed that. Then indeed you get the error message

! You can't use `macro parameter character #' in restricted horizontal mode.

What you have to do is remove the full two lines of the definition, i.e., the lines

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
Hendrik Vogt
  • 37,935