1

I'm creating a style file to use as a template for submissions to a specific journal. That journal requires a short title in the header. I could easily hard-code such a short title in the style file itself, following the answer to Page header alternatively author name and short title, but that's clearly not a good solution in this case, as I would need to change the template .sty file for every document I write. Any suggestions how I can do this? Dummy lines with \shorttitle are commented out in the MWE below.

\documentclass{article}
\usepackage{lipsum,filecontents}
\begin{filecontents}{mystyle.sty}
%% My package starts here
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mystyle}
\usepackage{titling}
\usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[R]{\thetitle\ \thepage} % Instead of this
%   \fancyhead[R]{\theshorttitle\ \thepage} % do something like this
\endinput
%% And ends here
\end{filecontents}
\usepackage{mystyle}

\begin{document}
\title{This is my long title}
%\shorttitle{This is my short title} % This short title should not be printed here - only in the header
\maketitle
\lipsum[1-6]
\end{document}
  • How about using a key-value interface for your command/style file? – user31729 Apr 23 '14 at 15:14
  • @ChristianHupfer I have no idea what that means. – Sverre Apr 23 '14 at 15:15
  • Something like \usepackage[shorttitle={Yet another sophisticated Title]{mystyle} as class/style option, e.g. created with xkeyval package? – user31729 Apr 23 '14 at 15:18
  • @ChristianHupfer Still way over my head :) – Sverre Apr 23 '14 at 15:18
4

It seems you can do what you want by defining a command in the .sty such as

\newcommand\@shorttitle{}
% define \theshorttitle to what is given
\newcommand\shorttitle[1]{\renewcommand\@shorttitle{#1}}

You can then use \@shorttitle in the .sty file in place of where you need it (e.g. defining the header; just use \@shorttitle instead of \theshorttitle). You can set the short title from your main document as you suggest, with

\shorttitle{This is my short title}

Hope this helps.

  • Usually, commands beginning with \the... indicate that they are purposed counter output formatting, not for titles itself. And the usage of \def is not necessary here where the safer \newcommand or \renewcommand would suffice. – user31729 Apr 23 '14 at 15:12
  • @ChristianHupfer If phfaist's suggestion is essentially correct, though, please edit the answer to reflect your objections. – Sverre Apr 23 '14 at 15:17
  • @Sverre: They are essentially correct, I wanted to indicate rather a matter of style, not more or less. – user31729 Apr 23 '14 at 15:19
  • 1
    @ChristianHupfer I understood that. Yet, please edit his answer so that it ends up being a suggestion I (and others who read this) can plug into a preamble or .sty file. – Sverre Apr 23 '14 at 15:20
  • @Sverre: I could (possible) edit his answer, but this is not my task. – user31729 Apr 23 '14 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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