There is \providecommand
that defines a macro if it is not yet defined. Together with \renewcommand
you have your "\extranewcommand
":
\providecommand{\foo}{}
\renewcommand{\foo}[1]{bar: #1}
Or you can switch to the plain TeX primitives (other syntax!), e.g.:
\long\def\foo#1{bar: #1}
(\renewcommand
and friends without star use \long\def
and if the star form is given, \def
without \long
is used. Also the parameters are specified differently.)
\declarecommand
A definition of the "requested" \declarecommand
that calls \providecommand
and \renewcommand
together:
\documentclass{article}
\makeatletter
\newcommand*{\declarecommand}{%
\@star@or@long\declare@command
}
\newcommand*{\declare@command}[1]{%
\provide@command{#1}{}%
% \let#1\@empty % would be more efficient, but without error checking
\renew@command{#1}%
}
\makeatother
\begin{document}
\declarecommand*{\foo}{\typeout{foo 1: \meaning\foo}}
\foo
\declarecommand{\foo}{\typeout{foo 2: \meaning\foo}}
\foo
\declarecommand*{\foo}[1]{\typeout{foo #1: \meaning\foo}}
\foo{3}
\end{document}
Result:
foo 1: macro:->\typeout {foo 1: \meaning \foo }
foo 2: \long macro:->\typeout {foo 2: \meaning \foo }
foo 3: macro:#1->\typeout {foo #1: \meaning \foo }
I am not sure if you are searching really for long side captions, but otherwise, this is a way using minipages for the main text and adjustbox
package to have top aligned images:
\documentclass[a4paper]{article}
\usepackage[export]{adjustbox}%
\usepackage{lipsum,graphicx}
\parskip1em
\def\capR#1#2{\includegraphics[width=.3\linewidth,valign=t]{#1}%
\hfill\begin{minipage}[t]{.6\textwidth}#2\end{minipage}}
\def\capL#1#2{\begin{minipage}[t]{.6\textwidth}#2\end{minipage}
\hfill\includegraphics[width=.3\linewidth,valign=t]{#1}}
\begin{document}
\capR{example-image-9x16}{\lipsum[2]}
\capR{example-image-a}{\lipsum[3]}
\capL{example-image-a}{\lipsum[4]}
\end{document}
For the secondary question, you can use an \ifoddpage
conditional of the changepage
or ifoddpage
packages (here a MWE with the former).
Edit:
If wrapping text is needed, another approach is a wrapfigure
inside a minipage
. This approach also solve messing you with \ifoddpage testings using the I
position and twoside
. The problem then is when the text is too short. Rhen the height of the minipage
environment will be less that the height of the image. But fortunately you can force the height of the minipages. Example:

\documentclass[a4paper,twoside]{article}
\usepackage{lipsum,graphicx,calc}
\usepackage{wrapfig}
\parskip1em\parindent0pt
\intextsep0pt
\newlength\gh \newlength\gw
\def\ImgNW#1#2{
\def\mygraphic{\includegraphics[width=.25\linewidth]{#1}}
\setlength\gh{\heightof{\mygraphic}}
\setlength\gw{\widthof{\mygraphic}}
\begin{minipage}[t][\gh+1em]{\textwidth}
\begin{wrapfigure}{I}[0pt]{0.25\textwidth}
\includegraphics[width=\linewidth]{#1}
\end{wrapfigure}#2
\end{minipage}\par}
\def\ImgW#1#2{
\def\mygraphic{\includegraphics[width=.25\linewidth]{#1}}
\setlength\gh{\heightof{\mygraphic}}
\setlength\gw{\widthof{\mygraphic}}
\begin{minipage}[t]{\textwidth}
\begin{wrapfigure}{I}[0pt]{0.25\textwidth}
\includegraphics[width=\linewidth]{#1}
\end{wrapfigure}#2
\end{minipage}\par}
\begin{document}
\ImgNW{example-image-9x16}{\lipsum[2]}
\ImgW{example-image-a}{\parskip1em\lipsum[3-4]}
\ImgW{example-image-b}{\lipsum[4]}
\newpage
\ImgW{example-image-c}{\lipsum[5]}
\ImgNW{example-image-9x16}{\lipsum[6]}
\ImgW{example-image-1x1}{\lipsum[7]}
\end{document}
Best Answer
If you can work with
XeLaTeX
orLuaLaTeX
,fontawesome
package provides\faCamera
and\faCameraRetro
icons. (Update:fontawesome
also works with pdflatex since version 4.3.0)