1

Consider the following source :

\documentclass[a4paper,12pt]{article}
\begin{document}

\newcounter{categorycounter} \setcounter{categorycounter}{0} \newenvironment{categoryname}[1][]{\stepcounter{categorycounter}\S\thecategorycounter.{\bf{ #1}}}{}

\begin{categoryname}{First category}\end{categoryname}

First category consists of blah blah blah.\newline

\begin{categoryname}{Second category} \end{categoryname}

Second category consists of bluh bluh bluh.\newline

\end{document}

I get the following ouptut :

enter image description here

Now, I want the category name to be in bold face, as indicated by my \bf command above. Why is it ignored ? What can I do to fix this ?

Here is the output I want :

enter image description here

user40960
  • 811
  • I didn't check if this is the problem, but as a blind shot, it's \textbf{#1} --- \bf is deprecated (since 30 years!) and does not have any argument, it's just a switch. – Rmano Jan 11 '22 at 10:42
  • Also, never use \newline in text... https://tex.stackexchange.com/questions/153506/insert-a-new-line-without-newline-command – Rmano Jan 11 '22 at 10:43

1 Answers1

3
  1. Use \bfseries instead of \bf

  2. Your main problem is the [] in the command definition that makes it to expect an optional argument #1 ... But you expect to use #1 as a mandatory one.

See changed code that gives your requested output

\documentclass[a4paper,12pt]{article}
\begin{document}

\newcounter{categorycounter} \setcounter{categorycounter}{0} \newenvironment{categoryname}[1]{\stepcounter{categorycounter}\S\thecategorycounter.{~{\bfseries #1}}}{}

\begin{categoryname}{First category}\end{categoryname}

First category consists of blah blah blah.

\begin{categoryname}{Second category} \end{categoryname}

Second category consists of bluh bluh bluh.

\end{document}

Edit: removed the \newline that doesn't offer something as mentioned in the comments...

Also you may want something inside the environment and not outside of it... In other case just create a command and not an environment.

koleygr
  • 20,105