2

I would like to add an optional argument to my macro

\documentclass[french]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage[a4paper]{geometry} \usepackage{babel} \NewDocumentCommand{\cpm}{ O {continue par morceaux} m }{continues par morceaux } \begin{document} Singular \cpm{}, Plural \cpm{s} \end{document} 

Result wanted is :

Singular continue par morceaux, Plural continues par morceaux

What I have currently is :

Singular continues par morceaux, Plural continues par morceaux

1
  • I guess you want \NewDocumentCommand{\cpm}{s}{continue\IfBooleanT{#1}{s} par morceaux} to be used as \cpm{} or \cpm* Commented Jan 2 at 15:09

1 Answer 1

3

Here's a solution that uses the "classic LaTeX" \newcommand directive to define \cpm. Note that in "classic LaTeX" syntax an optional argument, if provided, must be encased in square brackets, not curly braces.

enter image description here

\documentclass[french]{article} \usepackage[T1]{fontenc} %\usepackage[utf8]{inputenc} % that's the default nowadays \usepackage{babel} \usepackage{lmodern} \usepackage[a4paper]{geometry} \newcommand{\cpm}[1][]{continue#1 par morceaux} \begin{document} Singular: \cpm; plural: \cpm[s]. \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.