2

I wish to create a fancy header with an optional logo. If the logo was not defined by the user using

\logo{some-file.pdf}

the document would use the default logo ('TFPL.pdf').

My solution

\providecommand*{\logo}[1]{\gdef\@logo{#1}}
\providecommand*{\@logo}{TFPL.pdf}

works well, but because of some reasons I want to define the default logo-file with a macro:

\newcommand*{\logodefault}{TFPL.pdf}   
\providecommand*{\logo}[1]{\gdef\@logo{#1}}
\providecommand*{\@logo}{\logodefault}

But I get an error:

(/usr/share/texmf/tex/context/base/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) (/usr/share/texmf/tex/latex/base/article.cls)

! LaTeX Error: File `TFPL.pdf' not found.

My MWE:

\documentclass[a4paper,9pt]{article}

\usepackage{TFPL}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{epsfig}
\DeclareGraphicsExtensions{.pdf,.jpg}
\usepackage{epstopdf}

\usepackage{lipsum}

\begin{document}

\section{One}\indent
\lipsum[1-8]
\end{document}

TFPL.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{TFPL}[2016/08/02 Thinfilm]

\RequirePackage{xstring} %% if-else   
\DeclareOption*{\PackageWarning{Thinfilm}{Unknown ‘\CurrentOption’... te marha}}
\ProcessOptions\relax

%%----------Page--------------------------------------------------------------------------
\RequirePackage[margin=2.5cm, top=4cm, bottom=3cm, headsep=2cm]{geometry}
%%----------Header------------------------------------------------------------------------

\newcommand*{\logodefault}{TFPL.pdf}   
\providecommand*{\logo}[1]{\gdef\@logo{#1}}
\providecommand*{\@logo}{\logodefault}

\RequirePackage{lastpage}
\RequirePackage{fancyhdr}       
  \pagestyle{fancy}
  \fancyhf{}    
  \rhead{\includegraphics[height=1cm]{\@logo}}
  \lhead{\title}
  \rfoot{Page \thepage / \pageref{LastPage}}

Why does LaTeX not found the file 'TFPL.pdf' in the second (defined via macro) case?

1
  • 1
    note article class doesn't have a 9pt option, and epsfig shouldn't be loaded unless you need to emulate a latex2.09 document from 1990. your graphics settings seem very inconsistent, you have specified just pdf and jpg file extensions but have loaded epstopdf which is for including eps files, also \indent after a section heading does nothing. Sep 2, 2016 at 9:05

1 Answer 1

4

Don't give the file extension. You are defining what file types are allowed and in which priority they are looked for.

\begin{filecontents}{\jobname.sty}
    \NeedsTeXFormat{LaTeX2e}
    \ProvidesPackage{\jobname}[2017/01/22 Thinfilm]

    \RequirePackage{xstring} %% if-else   
    \DeclareOption*{\PackageWarning{Thinfilm}{Unknown ‘\CurrentOption’... te marha}}
    \ProcessOptions\relax

    %%----------Page--------------------------------------------------------------------------
    \RequirePackage{geometry}
    \geometry{margin=2.5cm, top=4cm, bottom=3cm, headsep=2cm,headheight=35pt}
    %%----------Header------------------------------------------------------------------------

    \newcommand*{\logodefault}{example-image}   
    \providecommand*{\logo}[1]{\gdef\@logo{#1}}
    \providecommand*{\@logo}{\logodefault}

    \RequirePackage{graphicx}
    \DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg}
    \RequirePackage{lastpage}
    \RequirePackage{fancyhdr}       
    \pagestyle{fancy}
    \fancyhf{}    
    \rhead{\includegraphics[height=1cm]{\@logo}}
    \lhead{\title}
    \rfoot{Page \thepage/\pageref{LastPage}}
\end{filecontents}
\documentclass[a4paper]{article}

\usepackage{\jobname}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}


\usepackage{lipsum}

\logo{example-image-a}
\begin{document}

\section{One}
\lipsum[1-8]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .