Based on the method indicated in this post, I want to make a \starredvariant
command that would take a command and output the definition of its starred variant.
The point is to be able to use a syntax similar to that of \newcommand
, i.e. using brackets as argument delimiters and embedding \WithSuffix
.
Edit. Such a command serves a purpose distinct from creating the starred/unstarred pair from scratch (e.g. using the boolean value of an argument of type s
, as suggested in several answers). The whole point is to customize a command that is not necessarily yours, or whose coding you do not wish to edit. In sum, the idea is to avoid a low-level redefinition.
Here is what I have come up with:
\NewDocumentCommand{\starredvariant}{mO{}O{}m}{\WithSuffix\newcommand#1*[#2][#3]{#4}}
MWE 1
\documentclass{article}\usepackage{suffix}\NewDocumentCommand{\starredvariant}{ m O{} O{} m} {\WithSuffix\newcommand#1*[#2][#3]{#4}}\newcommand{\inquotes}[2][]{#1 `#2'}\starredvariant{\inquotes}[2][]{#1 «\,#2\,»}\begin{document} \inquotes[fleur]{flower} \inquotes*[fleur]{flower} \inquotes*{flower}\end{document}
However, it does not work as expected here below in MWE 2.Any idea why?
MWE 2
\documentclass{article}\usepackage{changepage}\usepackage{suffix}\NewDocumentCommand{\starredvariant}{ m O{} O{} m}{\WithSuffix\newcommand#1*[#2][#3]{#4}}\newcommand{\tsltx}[1]{\normalfont\hspace{\parindent}`#1'}\starredvariant{\tslt}[1]{\normalfont\hspace{\parindent}`#1'}\begin{document}\begin{adjustwidth}{7em}{} \tsltx{The Atlantic wears away our coasts. The pressure of the current from the Pole deforms our western cliffs. This wall that shields us from the sea is being undermined from Saint-Valery-sur-Somme to Ingouville; huge blocks of rock tumble down, the sea churns clouds of boulders, our harbors are silted up with sand and shingle, the mouths of our rivers are barred. Every day a stretch of Norman soil is torn away and disappears under the waves. This tremendous activity, which has now slowed down, has had terrible consequences. It has been contained only by that immense spur of land we know as Finistère. The power of the flow of water from the Pole and the violence of the erosion it causes can be judged from the hollow it has carved out between Cherbourg and Brest. The formation of this gulf in the Channel at the expense of French soil goes back before historical times; but the last decisive act of aggression by the ocean against our coasts can be exactly dated. In 709, sixty years before Charlemagne came to the throne, a storm detached Jersey from France.}\end{adjustwidth}\vspace{3ex} \begin{adjustwidth}{7em}{} \tslt*{The Atlantic wears away our coasts. The pressure of the current from the Pole deforms our western cliffs. This wall that shields us from the sea is being undermined from Saint-Valery-sur-Somme to Ingouville; huge blocks of rock tumble down, the sea churns clouds of boulders, our harbors are silted up with sand and shingle, the mouths of our rivers are barred. Every day a stretch of Norman soil is torn away and disappears under the waves. This tremendous activity, which has now slowed down, has had terrible consequences. It has been contained only by that immense spur of land we know as Finistère. The power of the flow of water from the Pole and the violence of the erosion it causes can be judged from the hollow it has carved out between Cherbourg and Brest. The formation of this gulf in the Channel at the expense of French soil goes back before historical times; but the last decisive act of aggression by the ocean against our coasts can be exactly dated. In 709, sixty years before Charlemagne came to the throne, a storm detached Jersey from France.}\end{adjustwidth}\end{document}