[Tex/LaTex] Macro for Copy/Paste Image in Tex file

automationconversiongraphicsmacrostexstudio

I am writing a document that has a lot of images which are basically extracts from other PDF's.

What I do now is to copy the image, paste it in MSPaint and then I save it in the path folder that I'm using for \includegraphics{path}.

Is there any way one can simply this extra work by copying the image and paste it directly into the editor from the clipboard? I'm sure there is no straight-forward way, but can there be any trick that would convert the path or the image to a \includegraphics command?

I have noticed that if one pastes an image which is in clipboard to the tex editor, nothing happens. Is there any way to at least convert that image to the file path?

I have drawn what I have in mind, but please correct me if I'm dreaming of unicorns:
![Macro Sketch

Or does anyone know any faster way to do that? It sux when you have a lot of pictures.

EDIT: After reading the answers from Hamid I have realized that it is about setting up a Macro that:

  1. Saves the image from the clipboard to a file
  2. Reads the name and includes in a preset code (\begin{figure} \includegraphics{path_created_by_macro} \end{figure})
  3. Writes this in the editor.

Best Answer

If you are working in Linux you can use a bash script like this:

#!/bin/bash
for f in `ls  ./myImageDIR/*.png;`
do
  echo '
  \begin{figure}
        \includegraphics{'$f'}
  \end{figure}' 
done

and, following the tips in: How to execute shell script from LaTeX?, compile the file test.tex:

\documentclass{article}
\usepackage{graphicx}
\immediate\write18{./my-shell-script.sh > scriptoutput.tex}
\begin{document}
\input{scriptoutput.tex}
\end{document}

with the command line:

pdflatex -shell-escape -enable-write18 test.tex

If you need to add some text:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
text ...
\immediate\write18{./InsertOneImageLatex.sh  firstPicture}
\input{firstPicture.tex}
...other text...
\immediate\write18{./InsertOneImageLatex.sh  SecondPicture}
\input{SecondPicture.tex}
\end{document}

with InsertOneImageLatex.sh:

#!/bin/bash
echo '
\begin{figure}
        \includegraphics{'./myImageDIR/$1.png'}
\end{figure}' > $1.tex; 
Related Question