Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

To minimize the amount of copy-pasting I have to do between documents/projects, I've decided to create a separate file in which I renew the \maketitle command. This file (title.tex) should then be used as input for any project (in this case main.tex):

File main.tex:

\documentclass{article}
\input{/path/to/title}
\begin{document}
    \maketitle
\end{document}

File title.tex:

\usepackage[utf8]{inputenc}
\usepackage{geometry,graphicx}
\geometry{a4paper}
\renewcommand{\maketitle}{
    \includegraphics{image}
}

This doesn't work because the path provided for \includegraphics is relative. Making the path absolute would solve the problem, but that wouldn't make the file as portable as I would like.

Is there any way I can keep using a relative path for my image?

share|improve this question
    
    
Thanks for the suggestion, but using TEXINPUTS is not very portable. What would work (for me) is to read the path to the title.tex file from within the file and use that in the path to image, but I have no idea how. There is probably a more elegant way to do something like what I want. How do packages provide images? –  Silex Aug 12 '12 at 19:40
add comment

3 Answers 3

% Main.tex

\documentclass{article}
\usepackage{mytitle}
\begin{document}
    \MakeTitle{/path/to/image}
\end{document}
% mytitle.sty

\NeedsTeXFormat{LaTeX2e}[1994/06/01] 
\ProvidesPackage{mytitle}[2012/08/12 v0.01 LaTeX package to include title]  
\RequirePackage[utf8]{inputenc}
\RequirePackage[a4paper]{geometry}
\RequirePackage{graphicx}

\newcommand{\MakeTitle}[1]{\includegraphics{#1}}

\endinput 
share|improve this answer
add comment
up vote 2 down vote accepted

The answer was actually fairly simple: Turn title.tex into title.sty and place it in the texmf folder (together with the image file):

%% This package provides a modified title
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{title}[2012/08/13 v1 title]

\usepackage[utf8]{inputenc}
\usepackage{geometry,graphicx}
\geometry{a4paper}
\renewcommand{\maketitle}{
    \includegraphics{image}
}

\endinput
%%
%% End of file `title.sty'.

And in use the package in main.tex:

\documentclass{article}
\usepackage{title}
\begin{document}
    \maketitle
\end{document}

I have no idea if this is the proper way to do it, but it works well.

share|improve this answer
    
So what is difference with my yesterday answer? :-) –  Please don't touch Aug 13 '12 at 12:02
    
Your answer still required the path to image, which wasn't what I wanted - and apparently isn't necessary. Your answer did lead me to my own answer - so thanks a lot! –  Silex Aug 13 '12 at 12:22
add comment

You can also simply create a command that write the path of the directory with things to be included (image.png and title.tex) and put inside \input:

%main.tex    
\documentclass{article}
    \newcommand{\onlypath}{/some/path/things}
    \input{\onlypath/title}
    \begin{document}
        \maketitle
    \end{document}

as well as in the \includegraphics command:

%title.tex
\usepackage[utf8]{inputenc}
\usepackage{geometry,graphicx}
\geometry{a4paper}
\renewcommand{\maketitle}{
    \includegraphics{\onlypath/image}
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.