3

I am new to \LaTeX but am very excited to use it. At work I have a use for it for which it is perfect. Essentially we create the same report twice a month, which up til now has been done manually in Word. I would like to present this solution, which will offer huge time savings. Only problem is if there is any editing of code needed my boss will be hesitant. If I can present it in such a way that it just works he will not worry about other/future staff not understanding.

The rest of the document is working great, in the sense that all the moving parts change each runtime. But am stuck on going about making a command which would make the date stamp of the document either say middle or end of the current month? I think this should be possible.

Would trying to change something like \datetime be better than a new command? How would I go about doing either?

It will be going in the header as below.

\pagestyle{fancy}
\fancyhf{}

\chead{Mid-August}
3
  • I would not do this. What is if you for some reason recompile the Mid-August issue on september 1st? If the date is fix it should be set fixed in the code, too.
    – Tobi
    Aug 24, 2016 at 14:36
  • @Tobi: I assume that the OP will use a copy of the relevant file and changes the relevant contents and compiles that then?
    – user31729
    Aug 24, 2016 at 14:49
  • 1
    @Tobi Just like Christian says. I believe it is easier to have it "just work" in normal usage and have to be edited for abnormal usage than always having to be manually edited. I do understand you concern though. Aug 24, 2016 at 14:53

1 Answer 1

4

TeX provides the \year, \month and \day count registers, having the relevant date of compilation time (unless explicitly manipulated)

Querying with \ifnum\day < 15 it's possible to ask whether it is the 'middle' of the month or rather towards the end. (Well, the precise definition is to specified ;-)

datetime is the predecessor of datetime2, but easier to use (in my opinion), \monthname[\the\month] prints the name of the month.

I explicitly used the optional argument to show the manipulated values of \month and \day, omitting the optional argument forces \monthname to use the current value of the \month count register, which is in principle correct too since the current month shall be used anyway for the heading.

\documentclass{article}

\usepackage{fancyhdr}
\usepackage[english]{babel}
\usepackage{datetime}
\usepackage{blindtext}

\pagestyle{fancy}
\fancyhf{}

\chead{\ifnum\day < 15
  Mid-%
  \else
  End-%
  \fi%
  \monthname[\the\month]%
}


\begin{document}
\blindtext[5]
\clearpage
\day=10
\month=5
\blindtext[5]


\end{document}
1
  • @swoopdewoopzoom: You're welcome. Happy TeXing!
    – user31729
    Aug 24, 2016 at 15:00

You must log in to answer this question.

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