2

How do I make the song number shown on the right side only when the pages are even?

\documentclass[10pt,a6paper,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[chorded]{songs}
\usepackage{setspace}
\usepackage{import}
\usepackage{xpatch}
\usepackage[top=0.5in, bottom=0.7in, left=0.5in, right=0.5in]{geometry}

\makeatletter
 \newcommand\myjustify{%%
 \ifSB@inverse\advance\leftskip\versenumwidth\fi%
 \SB@cbarshift%
 \parindent12pt
}

\renewcommand\chorusjustify{\myjustify}

\newindex{titleidx}{cbtitle}
\newindex{temasidx}{temasidx}
\newauthorindex{authidx}{authidx}
\titleprefixword{¡}

\begin{document}

\begin{songs}{titleidx,authidx}

\songpos{0}
\setlength{\cbarwidth}{0 pt}
\versesep=2pt plus 1pt minus 1pt
\renewcommand{\chorusfont}{\it}
\noversenumbers
\onesongcolumn
\setlength{\songnumwidth}{0.9 cm}

\beginsong{   A Casa Vete}[
   by={Anonimo},
   sr={Marcos 5:19; Lucas 8:38,39},
   cr={\copyright~2017.},
   li={Usado con permiso}]
\indexentry[temasidx]{Predicacion}
\indexentry[temasidx]{Evangelio}

\beginverse\singlespacing
A casa vete, y cuenta allí
Que Cristo te libró;
Que tus amigos vean en tí
Lo que él, por gracia, obró.
\endverse

\beginchorus\singlespacing
A casa vete y lo que en ti
Ha hecho Dios, que vean,
Y puede ser que los de allí   
Lo buscarán también
\endchorus

\beginverse\singlespacing
A casa vete, y cuenta allí
Que Cristo comprendió
Tu gran necesidad, y así
Su sangre derramó.
\endverse

\beginverse\singlespacing
Ve, cuenta a los de en derredor
Que él satisfará
Sus almas, puesto que en su amor
La cruz sufrido ha.
\endverse

\beginverse\singlespacing
Ve, cuenta a los de más allá
Que en Cristo hay perdón,
Y que él a todos salvará,
Si quieren salvación.
\endverse

\endsong

\beginscripture{Reina-Valera SBT Marcos 5:19}
Mas Jesús no se lo permitió, sino que le dijo: Vete a tu casa, a los tuyos,
y cuéntales cuán grandes cosas el Señor ha hecho contigo, y cómo tuvo misericordia de ti.
\endscripture

\beginsong{   A Jesuscristo ven}[
  by={Anonimo},
  sr={Revelation 1:1},
  cr={\copyright~2017.},
  li={Usado con permiso}]
\indexentry[temasidx]{Predicacion}
\indexentry[temasidx]{Evangelio}
\indexentry[temasidx]{Invitación}

\beginverse\singlespacing
A Jesucristo ven sin tardar,
Que entre nosotros hoy él está
Y te convida con dulce afán,
Tierno diciendo:``Ven".
\endverse

\beginchorus\singlespacing
¡Oh cuán grata nuestra reunión!
Cuando al fin en celestial mansión
Con él estemos en comunión,
Gozando eterno bien.
\endchorus

\beginverse\singlespacing
Piensa que él solo puede colmar
Tu triste pecho de gozo y paz,
Y porque anhela tu bienestar
Vuelve a decirte: ``Ven".
\endverse

\beginverse\singlespacing
Su voz escucha sin vacilar,
Y grato acepta lo que hoy te da;
Tal vez mañana no habrá lugar:
No te detengas, ven.
\endverse
\endsong

\end{songs}
\showindex{Indice de Himnos}{titleidx}
\showindex{Indice por autor}{authidx}
\showindex{Indice por temas}{temasidx}
\end{document}

Page 1 of songsbook Page 2 of songsbook

  • Please make your code a complete MWE (minimal working example). Currently your code does not compile due to the missing Himno files. To adopt the behaviour for odd and even pages, you probably have to change the \makeprelude command. – epR8GaYuh Jul 2 '18 at 13:23
  • I already add two songs to the code for example, what I would like is that when the page is even the song number appears on the right of the page – Jorge Lainez Jul 2 '18 at 14:28
3

This is tricky because TeX sometimes doesn't know the true page number on which document content will be printed until the very end, when it writes the output file (e.g., because it makes last-minute decisions to shift content to a different page during page-breaking). The typical way to get around this is to compile the document twice, and ask TeX to remember where things landed on the first compile to predict where they will land during the second compile.

Here's a solution that does this for your situation:

\newcommand\oldmakeprelude{}
\let\oldmakeprelude=\makeprelude
\newcommand\oddmakeprelude{\oldmakeprelude}
\newcommand\evenmakeprelude{\reversedprelude}
{\makeatletter\gdef\makeprelude{%
  \expandafter\providecommand\csname songpage-\theSB@songsnum-\thesongnum\endcsname
    {\thepage}%
  \protected@write\@auxout{}{\string\expandafter\string\gdef
    \protect\csname songpage-\theSB@songsnum-\thesongnum\string\endcsname{\thepage}}%
  \ifodd\csname songpage-\theSB@songsnum-\thesongnum\endcsname\relax
    \oddmakeprelude
  \else
    \evenmakeprelude
  \fi
}}

Then we just need to provide a definition of \reversedprelude that is a copy of \makeprelude from the songs package code, except with the song number and text positions swapped at the end. Here's such a definition pulled from version 3.0 of the package:

\newcommand\reversedprelude{}
{\makeatletter\gdef\reversedprelude{%
  \resettitles%
  \ifslides%
    \hbox to\hsize{{\hfil\stitlefont\relax\songtitle\hfil}}%
    \vskip5\p@%
    \hbox to\hsize{%
      \hfil%
      \vbox{%
        \divide\hsize\tw@\parskip\p@\relax%
        \centering\small\extendprelude%
      }%
      \hfil%
    }%
  \else%
    \ifdim\songnumwidth>\z@%
      \setbox\SB@boxii\hbox{{\SB@colorbox\snumbgcolor{%
        \hbox to\songnumwidth{%
          \printsongnum{\thesongnum}\hfil%
        }%
      }}}%
    \fi%
    \setbox\SB@box\vbox{%
      \ifdim\songnumwidth>\z@%
        \SB@dimen\wd\SB@boxii%
        \advance\SB@dimen3\p@%
        \ifpagepreludes\multiply\SB@dimen\tw@\fi%
        \advance\hsize-\SB@dimen%
      \fi%
      \ifpagepreludes\centering\else\SB@raggedright\fi%
      \offinterlineskip\lineskip\p@%
      {\stitlefont\relax%
       \songtitle\par%
       \nexttitle%
       \foreachtitle{(\songtitle)\par}}%
      \ifdim\prevdepth=\z@\kern\p@\fi%
      \parskip\p@\relax\tiny%
      \extendprelude%
      \kern\z@%
    }%
    \ifdim\songnumwidth>\z@%
      \hbox{%
        \ifdim\ht\SB@boxii>\ht\SB@box%
          \vtop{\box\SB@box}%
          \kern3\p@%
          \box\SB@boxii%
        \else%
          \copy\SB@box%
          \kern3\p@%
          \SB@colorbox\snumbgcolor{\vbox to\ht\SB@box{{%
            \hbox to\songnumwidth{%
              \printsongnum{\thesongnum}\hfil%
            }\vfil%
          }}}%
        \fi%
      }%
    \else%
      \unvbox\SB@box%
    \fi%
  \fi%
}}

Remember that this might position song numbers incorrectly after a change to your book until you compile the document twice consecutively.

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.