4

I'm trying to make a booklet in A7 size but my printer only work with A4 so I need to make a pdf that look more or less like this:

Sheet 1 (Front)

+-----+-----+-----+-----+

|--40--|--1--|--38--|--3--|

+-----+-----+-----+-----+

|--36--|--5--|--34--|--7--|

+-----+-----+-----+-----+

Sheet 1 (Back)

+-----+-----+-----+-----+

|--39--|--2--|--37--|--4--|

+-----+-----+-----+-----+

|--35--|--6--|--33--|--8--|

+-----+-----+-----+-----+

Where the numbers represent the number of the page and the number of pages is 40. The question is what commands I have to use to make it a reality.

Sorry for my poor english

  • 2
    Welcome! I'm afraid your project will take some time. First, do make sure that your A7 pages are not bleached or chemically treated as they will not be properly broken down by the bacteria etc. otherwise. I don't know how well it will work with pure paper and no rotting vegetables, so you might want to add some peelings or whatever you have handy. I'm not sure you can turn compost directly into paper, but you could use it to grow a tree. You could then use the tree to produce your A4 sheet. As I say, I hope you're not in a hurry! – cfr Aug 05 '16 at 02:03
  • Nicely done, english isn't my first language I THINK that I corrected the mistake.Now serious can you help me? – Adriel Carlos Aug 05 '16 at 02:23
  • Sorry. I have a twisted sense of humour. For the record, your English seems fine. (If I'd guessed English was not your first language, I wouldn't have left my earlier comment.) This is a duplicate I think. Let me see if I can find it. – cfr Aug 05 '16 at 02:46
  • No problem I prefer that people show my mistakes so I can improve, about being a duplicate the close I got is this: http://tex.stackexchange.com/questions/261431/print-eight-a6-pages-on-one-two-sided-a4-sheet-in-a-book-folding-order but what I'm trying is a little diferent. – Adriel Carlos Aug 05 '16 at 02:58
  • What the guy do in this tutorial: http://www.mostlymaths.net/2010/11/creating-a6-booklets-in-7-easy-steps.html is what I'm trying to do but I don't have a pdf but the text. Any help would be nice. – Adriel Carlos Aug 05 '16 at 03:06
  • Can't you just set the page size using the geometry package and print multiple pages on one sheet of A4 paper? – JPi Aug 05 '16 at 03:24
  • I can't get it right. But I've posted something for other people to work with or maybe something I've done will help you solve it yourself. Making the A7 PDF is easy. It is the bit after which is the problem, of course. – cfr Aug 05 '16 at 03:29
  • @JohnKormylo You just need to feed geometry a custom paper as it doesn't know about A7. (See below.) – cfr Aug 05 '16 at 03:33
  • This does A6 pages on A4: http://tex.stackexchange.com/questions/279042/print-a6-book-on-a4-double-sided-in-correct-order –  Aug 05 '16 at 03:48
  • Found this: https://tug.org/pracjourn/2006-3/venugopal-pocketbook/venugopal-pocketbook.pdf maybe someone can come witha idea to make it work – Adriel Carlos Aug 05 '16 at 04:16
  • If you don't mind listing the pages individually, my edited answer below should work, I think. – cfr Aug 05 '16 at 11:19
  • Those methods would work, too. It partly depends whether you prefer to reduce the compilation steps or reduce the need to specify aspects of the document manually. Also, think about how small you want the result to be. I usually am making A5 booklets and design the pages for A5. If you make the booklet for A5 and then re-compile to get an A7 booklet, everything obviously has to be reduced in size. That may or may not be what you want. – cfr Aug 05 '16 at 11:34
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Nov 23 '16 at 02:51

2 Answers2

6

This does not order the pages automatically, but it does seem to work.

Here's an A7 document with 40 pages. Call the result a7-40.pdf.

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode
% arara: pdflatex
\pdfminorversion=7
\documentclass[twoside]{article}
\usepackage{geometry}
\geometry{paperwidth=74mm,paperheight=105mm}
\usepackage{graphicx}
\pagestyle{empty}
\begin{document}
\centering
\scalebox{30}{1}\newpage
\scalebox{30}{2}\newpage
\scalebox{30}{3}\newpage
\scalebox{30}{4}\newpage
\scalebox{30}{5}\newpage
\scalebox{30}{6}\newpage
\scalebox{30}{7}\newpage
\scalebox{30}{8}\newpage
\scalebox{30}{9}\newpage
\scalebox{10}{10}\newpage
\scalebox{10}{11}\newpage
\scalebox{10}{12}\newpage
\scalebox{10}{13}\newpage
\scalebox{10}{14}\newpage
\scalebox{10}{15}\newpage
\scalebox{10}{16}\newpage
\scalebox{10}{17}\newpage
\scalebox{10}{18}\newpage
\scalebox{10}{19}\newpage
\scalebox{10}{20}\newpage
\scalebox{10}{21}\newpage
\scalebox{10}{22}\newpage
\scalebox{10}{23}\newpage
\scalebox{10}{24}\newpage
\scalebox{10}{25}\newpage
\scalebox{10}{26}\newpage
\scalebox{10}{27}\newpage
\scalebox{10}{28}\newpage
\scalebox{10}{29}\newpage
\scalebox{10}{30}\newpage
\scalebox{10}{31}\newpage
\scalebox{10}{32}\newpage
\scalebox{10}{33}\newpage
\scalebox{10}{34}\newpage
\scalebox{10}{35}\newpage
\scalebox{10}{36}\newpage
\scalebox{10}{37}\newpage
\scalebox{10}{38}\newpage
\scalebox{10}{39}\newpage
\scalebox{10}{40}
\end{document}

Now use pdfpages to create the A4 pages:

\documentclass[a4paper,twoside]{article}
\usepackage{pdfpages,geometry}
\geometry{scale=1,marginparsep=0pt,marginparwidth=0pt,landscape}
\begin{document}
\includepdf[nup=4x2,pages={40,1,38,3,36,5,34,7,  32,9,30,11,28,13,26,15,  24,17,22,19,20,21,18,23,  16,25,14,27,12,29,10,31, 8,33,6,35,4,37,2,39}]{a7-40}
\end{document}

A7 4x2 on A4

EDIT EDIT

Note that EDIT follows EDIT EDIT, which is logical but non-chronological.

To answer a query in comments, here is one way to add horizontal and vertical rules to divide the page evenly into quarters.

\documentclass[a4paper,twoside]{article}
\usepackage{pdfpages,geometry}
\geometry{scale=1,marginparsep=0pt,marginparwidth=0pt,landscape}
\begin{document}
\newsavebox\adrielhrule
\sbox\adrielhrule{\vrule height .2pt depth .2pt width \paperwidth}
\newsavebox\adrielvrule
\sbox\adrielvrule{\hspace*{-.2pt}\vrule height \paperheight depth 0pt width .4pt}
\includepdf[nup=4x2,pages={40,1,38,3,36,5,34,7,  32,9,30,11,28,13,26,15,  24,17,22,19,20,21,18,23,  16,25,14,27,12,29,10,31, 8,33,6,35,4,37,2,39}, picturecommand={%
    \setlength\unitlength{1mm}% modified from Ignasi's answer at http://tex.stackexchange.com/a/64745/
    \put(0,105){\usebox{\adrielhrule}}%
    \put(148.5,0){\usebox{\adrielvrule}}%
  }]{a7-40}
\end{document}

dividers

EDIT

To make this more convenient, it would be nice to have TeX figure out the page order and automatically add blank pages, if necessary, to produce a complete signature.

This solution uses expl3 and a little help from egreg to achieve just this.

\adrielbooklet[<other pdfpages options>]{<no. of pages>}{<pdf filename>}

will include the first <no. of pages> from <pdf filename>, arranging them in the appropriate order and applying <other pdfpages options>.

Complete code with examples:

\documentclass[a4paper,twoside]{article}
\usepackage{pdfpages,geometry,xparse}
\geometry{scale=1,marginparsep=0pt,marginparwidth=0pt,landscape}
\ExplSyntaxOn
\int_new:N \l_adriel_pages_int
\int_new:N \l_adriel_total_int
\int_set:Nn \l_adriel_pages_int { 1 }
\int_set:Nn \l_adriel_total_int { 1 }
\tl_new:N \l_adriel_pages_tl
\tl_new:N \l_adriel_pdfopts_tl
\cs_new_protected_nopar:Npn \adriel_pageorder:n #1
{
  \int_compare:nTF
  {
    \int_mod:nn { #1 } { 4 }  = 0
  }
  {
    \int_set:Nn \l_adriel_total_int { #1 }
  }
  {
    \int_set:Nn \l_adriel_total_int { #1 + 4 - \int_mod:nn { #1 } { 4 } }
  }
  \int_set:Nn \l_adriel_pages_int { \l_adriel_total_int - 1 }
  \int_compare:nTF
  {
    \l_adriel_total_int > #1
  }
  {
    \tl_clear:N \l_adriel_pages_tl
  }
  {
    \tl_set:NV \l_adriel_pages_tl \l_adriel_total_int
  }
  \int_do_while:nn
  {
    \l_adriel_pages_int > 0
  }
  {
    \int_if_odd:nTF { \l_adriel_pages_int }
    {
      \int_compare:nTF
      {
        ( \l_adriel_total_int - \l_adriel_pages_int ) > #1
      }
      {
        \tl_put_right:Nn \l_adriel_pages_tl { , }
      }
      {
        \tl_put_right:Nx \l_adriel_pages_tl { , \int_eval:n { \l_adriel_total_int - \l_adriel_pages_int } }
      }
    }
    {
      \int_compare:nTF
      {
        \l_adriel_pages_int > #1
      }
      {
        \tl_put_right:Nn \l_adriel_pages_tl { , }
      }
      {
        \tl_put_right:Nx \l_adriel_pages_tl { , \int_eval:n { \l_adriel_pages_int } }
      }
    }
    \int_decr:N \l_adriel_pages_int
  }
}
\cs_new_protected_nopar:Npn \adriel_includepdf:nn #1 #2
{
  \includepdf[#1]{#2}
}
\cs_generate_variant:Nn \adriel_includepdf:nn { V }
\cs_new_protected_nopar:Npn \adriel_booklet:nnn #1 #2 #3
{
  \adriel_pageorder:n { #2 }
  \tl_set:Nx \l_adriel_pdfopts_tl { {pages={\l_adriel_pages_tl}} }
  \tl_put_right:Nn \l_adriel_pdfopts_tl { , #1 }
  \adriel_includepdf:Vn \l_adriel_pdfopts_tl { #3 }
}
\NewDocumentCommand \adrielbooklet { O {} m m }
{
  \adriel_booklet:nnn { #1 } { #2 } { #3 }
}
\ExplSyntaxOff
\begin{document}
\adrielbooklet[nup=4x2]{39}{a7-40}
\adrielbooklet[nup=4x2]{40}{a7-40}
\adrielbooklet[nup=4x2]{38}{a7-40}
\adrielbooklet[nup=4x2]{37}{a7-40}
\end{document}

This produces 4 booklets:

4 auto-booklets

EDIT EDIT EDIT

Here's a (mostly) expl3 version with dividing lines:

\documentclass[a4paper,twoside]{article}
\usepackage{pdfpages,geometry,xparse}
\geometry{scale=1,marginparsep=0pt,marginparwidth=0pt,landscape}
\ExplSyntaxOn
\int_new:N \l_adriel_pages_int
\int_new:N \l_adriel_total_int
\int_set:Nn \l_adriel_pages_int { 1 }
\int_set:Nn \l_adriel_total_int { 1 }
\tl_new:N \l_adriel_pages_tl
\tl_new:N \l_adriel_pdfopts_tl
\cs_new_protected_nopar:Npn \adriel_pageorder:n #1
{
  \int_compare:nTF
  {
    \int_mod:nn { #1 } { 4 }  = 0
  }
  {
    \int_set:Nn \l_adriel_total_int { #1 }
  }
  {
    \int_set:Nn \l_adriel_total_int { #1 + 4 - \int_mod:nn { #1 } { 4 } }
  }
  \int_set:Nn \l_adriel_pages_int { \l_adriel_total_int - 1 }
  \int_compare:nTF
  {
    \l_adriel_total_int > #1
  }
  {
    \tl_clear:N \l_adriel_pages_tl
  }
  {
    \tl_set:NV \l_adriel_pages_tl \l_adriel_total_int
  }
  \int_do_while:nn
  {
    \l_adriel_pages_int > 0
  }
  {
    \int_if_odd:nTF { \l_adriel_pages_int }
    {
      \int_compare:nTF
      {
        ( \l_adriel_total_int - \l_adriel_pages_int ) > #1
      }
      {
        \tl_put_right:Nn \l_adriel_pages_tl { , }
      }
      {
        \tl_put_right:Nx \l_adriel_pages_tl { , \int_eval:n { \l_adriel_total_int - \l_adriel_pages_int } }
      }
    }
    {
      \int_compare:nTF
      {
        \l_adriel_pages_int > #1
      }
      {
        \tl_put_right:Nn \l_adriel_pages_tl { , }
      }
      {
        \tl_put_right:Nx \l_adriel_pages_tl { , \int_eval:n { \l_adriel_pages_int } }
      }
    }
    \int_decr:N \l_adriel_pages_int
  }
}
\cs_new_protected_nopar:Npn \adriel_includepdf:nn #1 #2
{
  \includepdf[#1]{#2}
}
\cs_generate_variant:Nn \adriel_includepdf:nn { V }
\cs_new_protected_nopar:Npn \adriel_booklet:nnn #1 #2 #3
{
  \adriel_pageorder:n { #2 }
  \tl_set:Nx \l_adriel_pdfopts_tl { {pages={\l_adriel_pages_tl}} }
  \tl_put_right:Nn \l_adriel_pdfopts_tl { , #1 }
  \adriel_includepdf:Vn \l_adriel_pdfopts_tl { #3 }
}
\NewDocumentCommand \adrielbooklet { O {} m m }
{
  \adriel_booklet:nnn { #1 } { #2 } { #3 }
}
\box_new:N \l_adriel_hline_box
\box_new:N \l_adriel_vline_box
\hbox_set:Nn \l_adriel_hline_box { \vrule height .2pt depth .2pt width \paperwidth }
\hbox_set:Nn \l_adriel_vline_box { \hspace*{-.2pt} \vrule height \paperheight depth 0pt width .4pt }
\NewDocumentCommand \adrielhrule { }
{
  \box_use:N \l_adriel_hline_box
}
\NewDocumentCommand \adrielvrule { }
{
  \box_use:N \l_adriel_vline_box
}
\ExplSyntaxOff
\begin{document}
\adrielbooklet
  [nup=4x2,
  picturecommand={%
    \setlength\unitlength{1mm}% modified from Ignasi's answer at http://tex.stackexchange.com/a/64745/
    \put(0,105){\adrielhrule}%
    \put(148.5,0){\adrielvrule}%
  }%
  ]{40}{a7-40}
\end{document}

auto-version with dividers

cfr
  • 198,882
  • 2
    Great answer! In case one wants a semiautomatic way of generating the page interval, here's a Python one liner (just use the correct total of pages and run it in the terminal) python -c 'print((lambda h: reduce(lambda x, y : x + [ h + 1 - y, y ], range(1,h,2), []))(40))' – Paulo Cereda Aug 05 '16 at 14:44
  • @PauloCereda That's really helpful, thanks. I was wondering about a way to do this within TeX (I don't know Python), but that is neat. – cfr Aug 05 '16 at 16:01
  • Thanks, one more thing can you add some command so that the A4 show lines to horizontal and vertical a4 halfs? – Adriel Carlos Aug 05 '16 at 21:55
  • @AdrielCarlos Please see either EDIT EDIT or EDIT EDIT EDIT above. EDIT may or may not be of interest and is sandwiched between EDIT EDIT and EDIT EDIT EDIT, just to confuse things. – cfr Aug 06 '16 at 21:51
  • @PauloCereda That is also a lot more concise than the inline method I came up with above! – cfr Aug 06 '16 at 21:52
3

not sure if this fits the page rules, but you can probably do that with a tool like "pdf toolkit" (pdftk):

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

in my opinion it is better to keep the output of tex linear and apply the reordering later for print, but i'm a noob. :-)

edit: actually pdfnup might be better suited:

http://manpages.ubuntu.com/manpages/wily/man1/pdfnup.1.html

  • pdfpages uses pdftk (or it might be the other way around), but I definitely agree with the sentiment of keeping TeX output linear. The PDF should be readable – the printer should handle printing :) – Sean Allred Aug 06 '16 at 22:27