3

Emacs has a buit-in library to generate a landscape calendar with the function cal-tex-cursor-month-landscape. I am using TexLive 2012 on a OSX. The calendar image gets truncated on portrait orientation paper -- i.e., TexLive 2012 does not know to print the image in landscape. How can I use cal-tex-cursor-month-landscape to properly generate a landscape calendar using TexLive 2012?

%   This buffer was produced by cal-tex.el.
%   To print a calendar, type
%       M-x tex-buffer RET
%       M-x tex-print  RET
\documentclass[12pt]{article}
\hbadness 20000
\hfuzz=1000pt
\vbadness 20000
\lineskip 0pt
\marginparwidth 0pt
\oddsidemargin  -2cm
\evensidemargin -2cm
\marginparsep   0pt
\topmargin      0pt
\textwidth      7.5in
\textheight     9.5in
\newlength{\cellwidth}
\newlength{\cellheight}
\newlength{\boxwidth}
\newlength{\boxheight}
\newlength{\cellsize}
\newcommand{\myday}[1]{}
\newcommand{\caldate}[6]{}
\newcommand{\nocaldate}[6]{}
\newcommand{\calsmall}[6]{}
%
\special{landscape}% 
\textwidth 9.5in{}% 
\textheight 7in{}% 
% 
\def\holidaymult{.08}% 
\fboxsep=0pt
\long\def\caldate#1#2#3#4#5#6{%
    \fbox{\hbox to\cellwidth{%
     \vbox to\cellheight{%
       \hbox to\cellwidth{%
          {\hspace*{1mm}\Large \bf \strut #2}\hspace{.05\cellwidth}%
          \raisebox{\holidaymult\cellheight}%
                   {\parbox[t]{.75\cellwidth}{\tiny \raggedright #4}}}
       \hbox to\cellwidth{%
           \hspace*{1mm}\parbox{.95\cellwidth}{\tiny \raggedright #3}}
       \hspace*{1mm}%
       \hbox to\cellwidth{#6}%
       \vfill%
       \hbox to\cellwidth{\hfill \tiny #5 \hfill}%
       \vskip 1.4pt}%
     \hskip -0.4pt}}}
{}% 
\renewcommand{\myday}[1]%
{\makebox[\cellwidth]{\hfill\large\bf#1\hfill}}
%
{}% 
\begin{document}% 
\pagestyle{empty}% 
\setlength{\cellwidth}{24cm}% 
\setlength{\cellwidth}{0.157143\cellwidth}
\setlength{\cellheight}{18cm}% 
\setlength{\cellheight}{0.166667\cellheight}
\ \par{}% 
\vspace*{-3cm}% 
\def\calmonth#1#2%
{\begin{center}%
\Huge\bf\uppercase{#1} #2 \\[1cm]%
\end{center}}%
\vspace*{-1.5cm}%
%
{}% 
\def\lastmonth{\hbox to\cellwidth{%
\vbox to\cellheight{%
\vfil  \hbox to\cellwidth{%
\hfil\scriptsize\begin{tabular}{@{\hspace{0mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{0mm}}}%
\multicolumn{7}{c}{March 2017}\\[1mm]
Su & Mo & Tu & We & Th & Fr & Sa\\[0.7mm]
 &  &  & 1 & 2 & 3 & 4\\[0.5mm]
5 & 6 & 7 & 8 & 9 & 10 & 11\\[0.5mm]
12 & 13 & 14 & 15 & 16 & 17 & 18\\[0.5mm]
19 & 20 & 21 & 22 & 23 & 24 & 25\\[0.5mm]
26 & 27 & 28 & 29 & 30 & 31 & 
\end{tabular}\hfil}\vfil}}}%
\def\nextmonth{\hbox to\cellwidth{%
\vbox to\cellheight{%
\vfil  \hbox to\cellwidth{%
\hfil\scriptsize\begin{tabular}{@{\hspace{0mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{1mm}}r@{\hspace{0mm}}}%
\multicolumn{7}{c}{May 2017}\\[1mm]
Su & Mo & Tu & We & Th & Fr & Sa\\[0.7mm]
 & 1 & 2 & 3 & 4 & 5 & 6\\[0.5mm]
7 & 8 & 9 & 10 & 11 & 12 & 13\\[0.5mm]
14 & 15 & 16 & 17 & 18 & 19 & 20\\[0.5mm]
21 & 22 & 23 & 24 & 25 & 26 & 27\\[0.5mm]
28 & 29 & 30 & 31 & 
\end{tabular}\hfil}\vfil}}}%
\calmonth{April}{2017}
\vspace*{-0.5cm}% 
\myday{Sunday}%% 
\myday{Monday}%% 
\myday{Tuesday}%% 
\myday{Wednesday}%% 
\myday{Thursday}%% 
\myday{Friday}%% 
\myday{Saturday}%% 
\\[.2cm]% 
\lastmonth\nextmonth\hspace*{-2\cellwidth}\caldate{ }{ }{}{}{}{}%
\caldate{ }{ }{}{}{}{}%
\caldate{ }{ }{}{}{}{}%
\caldate{ }{ }{}{}{}{}%
\caldate{ }{ }{}{}{}{}%
\caldate{ }{ }{}{}{}{}%
\caldate{April}{1}{}{}{91/274}{}% 
\hfill\\% 
\caldate{April}{2}{}{}{92/273}{}% 
\caldate{April}{3}{}{}{93/272}{}% 
\caldate{April}{4}{}{}{94/271}{}% 
\caldate{April}{5}{}{}{95/270}{}% 
\caldate{April}{6}{}{}{96/269}{}% 
\caldate{April}{7}{}{}{97/268}{}% 
\caldate{April}{8}{}{}{98/267}{}% 
\hfill\\% 
\caldate{April}{9}{}{}{99/266}{}% 
\caldate{April}{10}{}{}{100/265}{}% 
\caldate{April}{11}{}{}{101/264}{}% 
\caldate{April}{12}{}{}{102/263}{}% 
\caldate{April}{13}{}{}{103/262}{}% 
\caldate{April}{14}{}{}{104/261}{}% 
\caldate{April}{15}{}{}{105/260}{}% 
\hfill\\% 
\caldate{April}{16}{}{}{106/259}{}% 
\caldate{April}{17}{}{}{107/258}{}% 
\caldate{April}{18}{}{}{108/257}{}% 
\caldate{April}{19}{}{}{109/256}{}% 
\caldate{April}{20}{}{}{110/255}{}% 
\caldate{April}{21}{}{}{111/254}{}% 
\caldate{April}{22}{}{}{112/253}{}% 
\hfill\\% 
\caldate{April}{23}{}{}{113/252}{}% 
\caldate{April}{24}{}{}{114/251}{}% 
\caldate{April}{25}{}{}{115/250}{}% 
\caldate{April}{26}{}{}{116/249}{}% 
\caldate{April}{27}{}{}{117/248}{}% 
\caldate{April}{28}{}{}{118/247}{}% 
\caldate{April}{29}{}{}{119/246}{}% 
\hfill\\% 
\caldate{April}{30}{}{}{120/245}{}% 
\caldate{}{}{}{}{}{}%
\caldate{}{}{}{}{}{}%
\caldate{}{}{}{}{}{}%
\caldate{}{}{}{}{}{}%
\caldate{}{}{}{}{}{}%
\caldate{}{}{}{}{}{}%
\end{document}% 
  • 1
    The file should be processed with latex and dvips in order to get the desired result (I've just tried it and it works for me with TL2016). Running pdflatex on it says Non-PDF special ignored! which is the relevant \special{landscape} line. Are you using pdflatex? – Arash Esbati Mar 24 '17 at 9:55
  • You were faster, Arash :-) Besides that, adding landscape to the document class options should also help. – Jan Mar 24 '17 at 16:05
  • @ArashEsbati -- yes, I'm using pdflatex, so that appears to be the problem. @Jan -- I will try adding landscape to the document class later today and report back with the results (using pdflatex) -- thank you. – lawlist Mar 24 '17 at 16:41
  • @Jan -- I had a chance to test substituting the document class article with landscape, but that prevents the PDF from being generated by pdflatex. The following setting works: \usepackage[left=.2in,top=0.15in,papersize={8.5in,11.0in},landscape,twoside=false]{geometry}. I'll need to find the internal function responsible for generating the LaTeX code within Emacs and add that line, or take it one step further and put in a condition (if that is possible) for whether latex or pdflatex is used to compile (disregarding \special{landscape} if the latter condition exists. – lawlist Mar 24 '17 at 21:51
  • 1
    @Jan -- thank you -- I added a note to the answer that addresses your suggestion - greatly appreciated! – lawlist Mar 26 '17 at 16:31
2

As stated by @Arash Esbati, the problem was indeed due to the fact that pdflatex does not support \special{landscape} One solution is to replace the aforementioned code with a call to the geometry package that works with pdflatex. I chose to hardcode a let-bound value for cal-tex-preamble-extra that takes effect if the LANDSCAPE argument is used. I commented out (cal-tex-cmd "\\special" "landscape").

@Jan has pointed out in one of the comments above that landscape can be added to the document class such that it would look like \documentclass[landscape]{article}. The function cal-tex-preamble accepts one argument called args, but a look at the code reveals that it really only accepts one string that gets inserted into the square brackets. Since the argument SIZE is already being used, it would be necessary to concatenate that with the proposed landscape option. This would be a viable alternative to using the geometry package.

(defun cal-tex-insert-preamble (weeks landscape size &optional append)
  "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
Select the output buffer, and insert the preamble for a calendar
of WEEKS weeks.  Insert code for landscape mode if LANDSCAPE is
non-nil.  Use point-size SIZE.  Optional argument APPEND, if
non-nil, means add to end of buffer without erasing current contents."
  (let ((width "18cm")
        (height "24cm")
        (cal-tex-preamble-extra
          (when landscape
            (concat
              "\\usepackage"
              "[left=.25in,top=0.15in,papersize={8.5in,11.0in},"
              "landscape,twoside=false]{geometry}"))))
    (setq width "24cm"
          height "18cm")
    (unless append
      (cal-tex-preamble size)
      (if (not landscape)
          (progn
            (cal-tex-cmd "\\oddsidemargin -1.75cm")
            (cal-tex-cmd "\\def\\holidaymult" ".06"))
        ;; (cal-tex-cmd "\\special" "landscape")
        (cal-tex-cmd "\\textwidth 9.5in")
        (cal-tex-cmd "\\textheight 7in")
        (cal-tex-comment)
        (cal-tex-cmd "\\def\\holidaymult" ".08"))
      (cal-tex-cmd cal-tex-caldate)
      (cal-tex-cmd cal-tex-myday)
      (cal-tex-b-document)
      (cal-tex-cmd "\\pagestyle" "empty"))
    (cal-tex-cmd "\\setlength{\\cellwidth}" width)
    (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
                    (/ 1.1 (length cal-tex-which-days))))
    (cal-tex-cmd "\\setlength{\\cellheight}" height)
    (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
                    (/ 1.0 weeks)))
    (cal-tex-cmd "\\ \\par")
    (cal-tex-vspace "-3cm")))

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.