Add a period after each paragraph title

I tend to use \paragraph{text} to structure my text (instead of \subsubection for example). The text in the paragraph is printed bold and some extra spacing is inserted. I would like to alter this by having latex print a period after the bold text. I could achieve this effect by defining another macro like.

\newcommand{\myparagraph}[1]{\paragraph{#1.}}


Is there some way to achieve the same effect using a more latex-friendly way (like a \paragraphDelimiter variable)?

• You simply want to add a period to the paragraph title automatically? – Alenanno Sep 7 '16 at 9:40
• your code fragments are so small it is impossible to guess what you are doing. \paragraph is a fourth level section heading following section,subsection,subsubsection. Despite its name it doesn't have much to do with paragraphs of text. You could modify the definition copied from article class (which is only a line) or use any package that helps set up section formatting. – David Carlisle Sep 7 '16 at 9:44
• If you load titlesec, then you can do \titleformat{\paragraph}[runin]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}[.]. So if you write \paragraph{A title}, this will yield A title. in the resulting PDF. – Alenanno Sep 7 '16 at 9:49

Copy the definition of \paragraph from your class (here I used article) and modify it by just adding \maybe@addperiod as shown: it should be the last token in the last argument.

\documentclass{article}

\makeatletter
\renewcommand\paragraph{%
\@startsection{paragraph}
{4}
{\z@}
{3.25ex \@plus1ex \@minus.2ex}
{-1em}
}
}
\makeatother

\begin{document}

\paragraph{This is the title} And some text follows.

\paragraph{This is the title.} And some text follows.

\paragraph{Is this is a title?} And some text follows.

\end{document}


As you can see, the period is printed only if punctuation doesn't end the argument to \paragraph.

If you want a version that doesn't need looking for the definition:

\documentclass{article}
\usepackage{xparse}

\makeatletter
\let\latexparagraph\paragraph
\RenewDocumentCommand{\paragraph}{som}{%
\IfBooleanTF{#1}
{\latexparagraph*{#3}}
{\IfNoValueTF{#2}
}%
}
}
\makeatother

\begin{document}

\paragraph{This is the title} And some text follows.

\paragraph{This is the title.} And some text follows.

\paragraph{Is this is a title?} And some text follows.

\end{document}


• I think this may be a little over-engineered, but it works. I do also like Alenannos suggestion. – hfhc2 Sep 7 '16 at 10:48
• @hfhc2 If you happen to have a title ending with punctuation different from a period, the simpler solution won't work. – egreg Sep 7 '16 at 11:13
• Also check out the magisterial handling of titles \paragraph{Like this.'' } – Joe Corneli Sep 11 '16 at 21:19
• @JoeCorneli Which should work, I guess. ;-) – egreg Sep 11 '16 at 21:22

egreg's and Alenanno's solutions are great. For a simpler one, how about the following?

\documentclass{article}
\let\oldparagraph=\paragraph
\renewcommand\paragraph[1]{\oldparagraph{#1.}}
\begin{document}

\paragraph{Hello}

World.

\end{document}