# Numbered \newcommand without enumerate

How to add numbered problems within chapters and sections but not with enumerate.

Problem must have variable as defined below.

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\newcommand{\prob}[1]{\vspace{.5cm}\noindent\textbf{\textsc{Problem}} $\left[#1 \right]$}
\begin{document}
\section{My first section}
\prob {1} This is problem.

\end{document}

• What are the errors you receive? – Werner Mar 31 '15 at 17:00
• I edited it. I want to add numbered \prob{} within sections or chapters. – vejn Mar 31 '15 at 17:03
• this could be handled with a theorem-style environment. pick a theorem style that doesn't set the text in italic. with amsthm, the definition environment would be appropriate. – barbara beeton Mar 31 '15 at 17:06
• How? Is there a way with \newcommand? With \newenvironment I must use \begin{...} ... \end{...} – vejn Mar 31 '15 at 17:08

Here is edited solution

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\newcounter{pro}[section]
\renewcommand{\thepro}{\thesection.\arabic{pro}}

\newcommand{\prob}[1]{%
\refstepcounter{pro}%
\begin{document}
\section{My first section}
\prob{4}  This is problem.
\prob{6}  This is problem.
\end{document}


Remark for bold small capitals this is another question

• Where to insert additional variable as I stated in \prob. This varable means max points of problem. So for example, in chapter 1 section 1 problem would look like: 1.1.1 Problem [4]. It would have 4 points. I like newcommand more because has less typing. What did you mean this is another que. for Remark? Thx – vejn Mar 31 '15 at 18:16
• OK, sorry i did not understand. I'll edit my code – touhami Mar 31 '15 at 18:17
• Just one more question. How to make numbered problem compatible with definitions and theorems. So after definition 1.1.1 goes 1.1.2 Problem [4] with \newcommand. – vejn Mar 31 '15 at 18:40
• add '\stepcounter{pro} to the definition of your definition environemnt. may be there is package to do this. – touhami Mar 31 '15 at 18:49

Here is a solution with the titlesec package; the \problem command is an unnumbered subsection. The titlesec package has an unnumbered key, which allows for a different formatting of numbered and unnumbered subsections. The problems will nevertheless be automatically numbered with an adhoc counter, and they can have a title, as an optional argument. As these subsections will most probably be the only type of unnumbered subsections, it shouldn't interfere with other settings of the document.

Note. I loaded the erewhon package (an extension to Adobe Utopia) for the reason that you seem to want a boldface smallcaps font, which doesn't exist in Latin Modern.

\documentclass[10pt,a4paper,oneside]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier, erewhon}
\usepackage{amsfonts, amssymb}
\usepackage[margin=3cm, showframe]{geometry}
\usepackage{etoolbox}

\usepackage[explicit]{titlesec}
\newcounter{problem}[section]
\newcommand\problem[1][]{\subsection*{#1}}
\titleformat{name=\subsection, numberless}[runin]%
{\stepcounter{problem}}{\bfseries\scshape{Problem~[\theproblem]}}%
{0.4em}{\ifblank{#1}{\hskip-0.333em.}{(#1).}}

\begin{document}

\section{A first section}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\problem[Test problem]
A first problem, with a title.

\problem
A second problem.

\bigskip

Some more text. Some more text. Some more text. Some more text. Some more text.

\section{A second section}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\problem[New test problem]
Another problem with a title.

\problem
A final problem.

\bigskip

Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\end{document}


• I couldn't compile it with texmaker. I got infinite loop. I should update some pacakges. – vejn Mar 31 '15 at 18:46
• Perhaps problem with erewhon? You can replace it with heuristica. Erewhon is relatively recent (1½ year or so, I think), Heuristica` a little older. – Bernard Mar 31 '15 at 19:02
• Since fancy fonts aren't necessary for the solution, why do you use them? – egreg Mar 31 '15 at 22:05
• Because the O.P. wants bold small caps, and Latin Modern fonts do not have such fonts. – Bernard Mar 31 '15 at 22:22