5

To create something like a diary, I am using a number of input files within 2 directories a MONTH directory named 01-12 and a day directory within each month...01-31

so

12/ (December) which has a file 12.tex which inputs 12/01/01.tex (there is also a 12/02/02.tex and so on...the day tex file calls a bunch of other files from the day directory)

The idea was to have currfile print out the the month directory name and the day directory name and so use that to create headers and chapter heads automatically. I would just need to put in the year and it wouldput the right day of the week and date on the correct page.

I started exploring this here: Using macros in Memoir chapter for a Diary but changed my method a bit and using this answer to my last question:

https://tex.stackexchange.com/a/220450/26651

I thought I had my solution...

I tried this:

\DeclareRobustCommand{\dateforheader}{\formatdate{\StrBehind{\currfiledir}{/}[\currfilesubdir]\StrBefore{\currlastdir}{/}}{\StrBefore{\parentfiledir}{/}}{2015}}

and I tried this

 \DeclareRobustCommand{\MyDay}{{\StrBehind{\currfiledir}{/}[\currfilesubdir]\StrBefore{\currlastdir}{/}}
 \DeclareRobustCommand{\MyMonth}{\StrBefore{\parentfiledir}{/}}

\formatdate{\MyDay}{\MyMonth}{2015}

hoping to use them in a page header

\makeoddhead{mypagestyle}{}{\dateforheader}{\thepage} 

This doesn't work.

nor does it work to just use the macro on the 12/01/01.tex page:

\dateforheader

though

\MyDay 
\MyMonth 

will work by themselves

my error messages:

./12/1/1.tex:4: Missing number, treated as zero. [{\dateforheader]
./12/1/1.tex:4: Undefined control sequence. [{\dateforheader]
./12/1/1.tex:4: Missing number, treated as zero. [{\dateforheader]
./12/1/1.tex:4: Missing number, treated as zero. [{\dateforheader]
./12/1/1.tex:4: Undefined control sequence. [{\dateforheader]
./12/1/1.tex:4: Missing number, treated as zero. [{\dateforheader]
./12/1/1.tex:4: Package datetime Error: Invalid Month number 0. [{\dateforheader]

UPDATE:

using @karlkoeller answer below I created a MWE but it doesn't seem to work for me so I thought I would test the individual macros using the MWE below:

Set up home directory inside is test.tex with this code:

\documentclass{memoir}
\usepackage{xstring}
\usepackage{datetime}
\usepackage{currfile}
\usepackage{import}

\StrBehind{\currfiledir}{/}[\currfilesubdir]
\StrBefore{\currfilesubdir}{/}[\MyDay]
\StrBefore{\currfiledir}{/}[\MyMonth]

\newcommand{\mydate}{\MyDay, \MyMonth}

\begin{document}
\input{8/8.tex}
\end{document} 

within the home directory there is a directory called 8 within that

a tex file called 8.tex with the following code:

 \input{8/1/1.tex}

also witin directory 8 is directory 1 with the 1.tex file with the code below... which I thought would test the marcros:

currfiledir:\currfiledir

part 1 of My Day: \StrBehind{\currfiledir}{/}

part 2 of My Day: \StrBefore{\currfilesubdir}{/}

MyMonth: \StrBefore{\currfiledir}{/}

date: \mydate

the results are below:

currfiledir: 8/1/

part 1 of My Day: 1/

part 2 of My Day:

MyMonth: 8

date: ,


any ideas what is wrong here?

  • You say \MyDay doesn't work. And then you say it does. It would be helpful if you posted a complete MWE with everything in one place. – cfr Jan 4 '15 at 4:18
  • Sorry, that was an error... it's edited. Will poste a MWE if the answer below doesn't help... though because of the multiple pieces I may have to post a zip file with directories... which is why I hesitated. – theobear Jan 4 '15 at 13:24
  • I've updated my question with a MWE – theobear Jan 5 '15 at 1:19
3

You have to save the results of string manipulations in macros, so that they can be used as arguments for \formatdate.

So, replace your code with

\StrBehind{\currfiledir}{/}[\currfilesubdir]
\StrBefore{\currfilesubdir}{/}[\MyDay]
\StrBefore{\currfiledir}{/}[\MyMonth]

The above lines have to be put at the beginning of each one of your <day>.tex files.

At this point \MyDay contains the day's number and \MyMonth the month's number and you can define

\DeclareRobustCommand{\dateforheader}{\formatdate{\MyDay}{\MyMonth}{2015}}

which has to be put in your main file.

MWE:

\documentclass{memoir}
\usepackage{xstring}
\usepackage{datetime}

%\usepackage{currfile}            % uncomment this line in your mainfile.tex
\newcommand{\currfiledir}{12/01/} % comment this line in your mainfile.tex

\usepackage{lipsum} % Just for the example

\StrBehind{\currfiledir}{/}[\currfilesubdir] % to be put in each <day>.tex
\StrBefore{\currfilesubdir}{/}[\MyDay]       % to be put in each <day>.tex
\StrBefore{\currfiledir}{/}[\MyMonth]        % to be put in each <day>.tex

\DeclareRobustCommand{\dateforheader}{\formatdate{\MyDay}{\MyMonth}{2015}} % to be put in your mainfile.tex

\makeoddhead{headings}{}{\dateforheader}{\thepage} % to be put in your mainfile.tex (change headings to mypagestyle)

\begin{document}
\lipsum[1]
\end{document} 

Output:

enter image description here

  • Thanks for your help, I tried it and ran into problems so I created a MWE. I've updated my question with the results. – theobear Jan 5 '15 at 1:18
  • @theobar I've added some comments in the code to distinguish where various part have to be put. Hope it is clear now. – karlkoeller Jan 5 '15 at 6:15

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.