Skip to main content
added 22 characters in body
Source Link
Zach
  • 141
  • 1
  • 7

Removing the extra \includegraphics isin output.pdf_tex does not enoughsolve the problem since each page in output.pdf contains parts of the drawings are contained in the other pages as welldrawing. I found a solution (proposed by Biber on launchpad.net) which uses a new definition of the "\includesvg" command:

  1. Your drawings must be in the folder "./Figures/";
  2. Your temporary files (".pdf", ".pdf_tex") will be added in the folder "./tmp/" (you don't need to create the "./tmp" folder it will be done automatically);
  3. The 3 following commands must be placed before '\begin{document}':

% 1 - Set the graphic paths

\graphicspath{ {./Figures/} {./.tmp/} }

% 2 - Command used to test if the compilation of the svg file is necessary (i.e., if the .svg file is more recent than the corresponding pdf file)

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

% 3 - Command that creates the ".pdf" and ".pdf_tex" from the ".svg". The workaround is in this command

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,\${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

With these three commands an svg file can be displayed using "\includesvg" (like we would use "\includegraphics"):

\begin{figure}
   \centering
   \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located at: ./Figures/My_Nice_SVG_File.svg
   \caption{My_Caption]
   \label{My_Label}
\end{figure}

Removing the extra \includegraphics is not enough since parts of the drawings are contained in the other pages as well. I found a solution (proposed by Biber on launchpad.net) which uses a new definition of the "\includesvg" command:

  1. Your drawings must be in the folder "./Figures/";
  2. Your temporary files (".pdf", ".pdf_tex") will be added in the folder "./tmp/" (you don't need to create the "./tmp" folder it will be done automatically);
  3. The 3 following commands must be placed before '\begin{document}':

% 1 - Set the graphic paths

\graphicspath{ {./Figures/} {./.tmp/} }

% 2 - Command used to test if the compilation of the svg file is necessary (i.e., if the .svg file is more recent than the corresponding pdf file)

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

% 3 - Command that creates the ".pdf" and ".pdf_tex" from the ".svg". The workaround is in this command

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,\${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

With these three commands an svg file can be displayed using "\includesvg" (like we would use "\includegraphics"):

\begin{figure}
   \centering
   \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located at: ./Figures/My_Nice_SVG_File.svg
   \caption{My_Caption]
   \label{My_Label}
\end{figure}

Removing the extra \includegraphics in output.pdf_tex does not solve the problem since each page in output.pdf contains parts of the drawing. I found a solution (proposed by Biber on launchpad.net) which uses a new definition of the "\includesvg" command:

  1. Your drawings must be in the folder "./Figures/";
  2. Your temporary files (".pdf", ".pdf_tex") will be added in the folder "./tmp/" (you don't need to create the "./tmp" folder it will be done automatically);
  3. The 3 following commands must be placed before '\begin{document}':

% 1 - Set the graphic paths

\graphicspath{ {./Figures/} {./.tmp/} }

% 2 - Command used to test if the compilation of the svg file is necessary (i.e., if the .svg file is more recent than the corresponding pdf file)

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

% 3 - Command that creates the ".pdf" and ".pdf_tex" from the ".svg". The workaround is in this command

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,\${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

With these three commands an svg file can be displayed using "\includesvg" (like we would use "\includegraphics"):

\begin{figure}
   \centering
   \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located at: ./Figures/My_Nice_SVG_File.svg
   \caption{My_Caption]
   \label{My_Label}
\end{figure}
deleted 6 characters in body
Source Link
Zach
  • 141
  • 1
  • 7

Removing the extra \includegraphics is not enough since the pdf pages contain partparts of mythe drawings are contained in the other pages as well. I found a solution (proposed by Biber on launchpad.net) which uses a new definition of the "\includesvg" command:

%######## Put all this code before the '\begin{document}' statement. ###########

  1. Your drawings must be in the folder "./Figures/";
  2. Your temporary files (".pdf", ".pdf_tex") will be added in the folder "./tmp/" (you don't need to create the "./tmp" folder it will be done automatically);
  3. The 3 following commands must be placed before '\begin{document}':

%Tell LaTeX where to look for graphics (the './.tmp% 1 /' folder will be used by the '\includesvg' command for- Set the inkscape PDF+TEX output, './Figures/' is where all my SVGs are stored.)graphic paths

\graphicspath{ {./Figures/} {./.tmp/} }

\graphicspath{ {./Figures/} {./.tmp/} }

%We'll never call this manually, it's just% 2 - Command used by the '\includesvg' command to avoid unnecessary rebuildingtest if the compilation of PDFs

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

%Here it comes... Itthe svg file is necessary that all our SVG files are collected (e.g. by symlinking) in only one folder (here it is called 'i./Figures/'e. If you want a different one, make sure to changeif the path in this command as well.

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:file is more recent than the corresponding pdf file)\s*[0-9]+" | tr

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

% 3 -d " Command that creates the ") ; sed -i.pdf" and "/page=$(($MAXPAGE+1))/,${/page=/d}" ${PDF_FILE}_tex; } } \input{./pdf_tex" from the ".tmp/#2svg".pdf_tex}} The workaround is in this command

%##############################################################

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,\${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

YouWith these three commands an svg file can then use the '\includesvg' command similarlybe displayed using "\includesvg" (though not so advancedlike we would use "\includegraphics") to '\includegraphics', e.g.

\begin{figure} \centering \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located/linked at: ./Figures/My_Nice_SVG_File.svg \caption{My_Caption] \label{My_Label} \end{figure}

\begin{figure}
   \centering
   \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located at: ./Figures/My_Nice_SVG_File.svg
   \caption{My_Caption]
   \label{My_Label}
\end{figure}

Removing the extra \includegraphics is not enough since the pdf pages contain part of my drawings. I found a solution (proposed by Biber on launchpad.net):

%######## Put all this code before the '\begin{document}' statement. ###########

%Tell LaTeX where to look for graphics (the './.tmp /' folder will be used by the '\includesvg' command for the inkscape PDF+TEX output, './Figures/' is where all my SVGs are stored.)

\graphicspath{ {./Figures/} {./.tmp/} }

%We'll never call this manually, it's just used by the '\includesvg' command to avoid unnecessary rebuilding of PDFs

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

%Here it comes... It is necessary that all our SVG files are collected (e.g. by symlinking) in only one folder (here it is called './Figures/'. If you want a different one, make sure to change the path in this command as well.

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

%##############################################################

You can then use the '\includesvg' command similarly (though not so advanced) to '\includegraphics', e.g.

\begin{figure} \centering \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located/linked at: ./Figures/My_Nice_SVG_File.svg \caption{My_Caption] \label{My_Label} \end{figure}

Removing the extra \includegraphics is not enough since parts of the drawings are contained in the other pages as well. I found a solution (proposed by Biber on launchpad.net) which uses a new definition of the "\includesvg" command:

  1. Your drawings must be in the folder "./Figures/";
  2. Your temporary files (".pdf", ".pdf_tex") will be added in the folder "./tmp/" (you don't need to create the "./tmp" folder it will be done automatically);
  3. The 3 following commands must be placed before '\begin{document}':

% 1 - Set the graphic paths

\graphicspath{ {./Figures/} {./.tmp/} }

% 2 - Command used to test if the compilation of the svg file is necessary (i.e., if the .svg file is more recent than the corresponding pdf file)

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

% 3 - Command that creates the ".pdf" and ".pdf_tex" from the ".svg". The workaround is in this command

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,\${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

With these three commands an svg file can be displayed using "\includesvg" (like we would use "\includegraphics"):

\begin{figure}
   \centering
   \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located at: ./Figures/My_Nice_SVG_File.svg
   \caption{My_Caption]
   \label{My_Label}
\end{figure}
Source Link
Zach
  • 141
  • 1
  • 7

Removing the extra \includegraphics is not enough since the pdf pages contain part of my drawings. I found a solution (proposed by Biber on launchpad.net):

%######## Put all this code before the '\begin{document}' statement. ###########

%Tell LaTeX where to look for graphics (the './.tmp /' folder will be used by the '\includesvg' command for the inkscape PDF+TEX output, './Figures/' is where all my SVGs are stored.)

\graphicspath{ {./Figures/} {./.tmp/} }

%We'll never call this manually, it's just used by the '\includesvg' command to avoid unnecessary rebuilding of PDFs

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

%Here it comes... It is necessary that all our SVG files are collected (e.g. by symlinking) in only one folder (here it is called './Figures/'. If you want a different one, make sure to change the path in this command as well.

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

%##############################################################

You can then use the '\includesvg' command similarly (though not so advanced) to '\includegraphics', e.g.

\begin{figure} \centering \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located/linked at: ./Figures/My_Nice_SVG_File.svg \caption{My_Caption] \label{My_Label} \end{figure}