# How to add an icon to a paragraph's margin?

I'd like a custom command or environment to add an image in the right margin at the top of a paragraph, which would look something like this:

Here's the icon (as a PNG) I'd like to use.

Related:

• Could you post a full compilable code using this specific environment? Nov 9, 2018 at 22:27
• I made the example image with Pages not TeX. I added the thumbnail image linked in the text above.
– M.R.
Nov 10, 2018 at 1:39
• What type of code input are you after? You talk about paragraphs and environments... just wondering since they aren't exactly the same.
– Werner
Nov 10, 2018 at 1:51

You didn't tell us anything about your environment, so I just picked one...quote, and provide \margfig.

\documentclass{article}
\usepackage{lipsum,graphicx,tabto,stackengine}
\newcommand\margfig[2][]{%
\leavevmode%
%  \tabto*{-40pt}% LEFT MARGIN
\tabto*{\dimexpr\linewidth+40pt\relax}% RIGHT MARGIN
\smash{\belowbaseline[-\ht\strutbox]{\makebox[0pt]%
%    [r]% LEFT MARGIN
[l]% RIGHT MARGIN
{\includegraphics[#1]{#2}}}}%
\tabto*{\TabPrevPos}%
}
\begin{document}
\lipsum[1]
\begin{quote}
\margfig[width=50pt]{example-image}
\lipsum[2]
\end{quote}
\lipsum[3]
\end{document}


RIGHT MARGIN VERSION

LEFT MARGIN VERSION