5

I want to to create a LaTeX document for taking notes of a book I'm reading.

I want the final document to look like this:

============

Page xy Here shall be the note xy..

Page ab Here shall be the note for page ab..

============

Furthermore I want the notes to be sorted in a way that the lowest page numbers are at the beginning of the document and the larger page numbers further down. My input in LaTeX should be something like this:

Page 836:      Here shall be the note for page number 836..
Page 144:      Here shall be the note for page number 144..

The result should be:

===

Page 144: Here shall be the note for page number 144..

Page 836: Here shall be the note for page number 836..

===

I've tried

\usepackage{amsthm}
\newtheorem{note}{Page}

but I don't get a satisfactory result.

Do you know a way to get the desired result?

I am glad at any help!

P.S.: Feel free to edit this question since I'm not a native English Speaker.

  • My first impression is that you don't need sorting as it is already sorted. I would probably generate a file with my notes (as in Table of Contents) and typeset it at the end of the document. – Malipivo May 19 '14 at 21:03
  • On a unix-alike system, you could keep a plain text file with lines of the form 836: Here shall be the note for page number 836.. and then use sort and sed to sort and format the result so you'd get sorted lines of the form \item[836] Here shall be the note for page number 836.. or whatever. Just add the top and bottom suggested in David Carlisle's answer and your notes would be ready to typeset. – cfr May 19 '14 at 22:18
6

Here's one way to do it (ab)using the nomencl package; automatic sorting is performed using MakeIndex:

\documentclass{article}
\usepackage{nomencl}
\usepackage{lipsum}
\makenomenclature

\renewcommand\nomname{Notes}
\renewcommand{\nomlabel}[1]{\bfseries Page~#1:\hfil}

\begin{document}

\mbox{}
\nomenclature{863}{\lipsum*[4]}
\nomenclature{144}{\lipsum*[3]}
\nomenclature{234}{\lipsum*[2]}
\nomenclature{14}{\lipsum*[5]}

\printnomenclature[0.75in]
\end{document}

enter image description here

If the document is called mydoc.tex, you should process it using

pdflatex mydoc
makeindex mydoc.nlo -s nomencl.ist -o mydoc.nls
pdflatex mydoc
  • Your example Document is exactly what it should look like! I use the program Texmaker on Windows and up to now I always used "Quick Build" and it did work all the time but now it doesn't. Shall I copy your last code lines into the command prompt? Why does "Quick Build" not work this time? – user50224 May 20 '14 at 8:10
  • 1
    @user50224 As I mentioned in my answer, you need to run MakeIndex. You need to compile your document as I explained at the end of my answer. I don't use TeXmaker, but you can use your "Quick Build" once, then run makeindex mydoc.nlo -s nomencl.ist -o mydoc.nls in the command prompt (replace "mydoc" with the name of your file), and then use "Quick Build" once again. – Gonzalo Medina May 20 '14 at 12:21
  • Well, thanks for your efforts. I tried it with the command prompt but after the second time pdflatex abc I just get: No pages of Output. Maybe I'm unlucky :/ P.S.: I had to type the whole path of my .tex file in the command prompt, when using pdflatex to get an response that was this different from can't find file – user50224 May 20 '14 at 18:23
  • 1
    @user50224 Instead of typing whole paths, please first move to the directory containing the .tex file. Do you know how to use the cd command to change directories? cd /path to the file/. Once there, you should simply invoke the commands as in my answer. – Gonzalo Medina May 20 '14 at 18:32
  • I wrote an answer because I can't post an image as a comment. Maybe you can have a look at it and tell me why it is not working. – user50224 May 20 '14 at 19:44
2

enter image description here

\documentclass{article}

\renewcommand*\descriptionlabel[1]{\hspace\labelsep
                                \normalfont\bfseries Page #1:}

\begin{document}

\begin{description}

\item[836]      Here shall be the note for page number 836..
\item[144]      Here shall be the note for page number 144..
\end{description}

\end{document}
  • Thanks, but do you also know how to sort the items as I mentioned in my question? – user50224 May 19 '14 at 22:22
  • 1
    @user50224 you have the word sort in the title but nothing in the question indicated sorting was needed, and you did not provide an example document (every question ought to have an example document) it's possible to sort on latex but traditionally an external program is used (makeindex, bibtex etc) I can't see why you'd need to sort or why you couldn't just sort the lines in your editor, just applying the unix sort command to the input file would fix it if the input was structured enough eg one line per item. – David Carlisle May 19 '14 at 22:36
  • @DavidCarlisle that's exactly what I proposed below =) out of curiosity, do you know how many items it is feasible to sort with TeX on a typical machine? – Bordaigorl May 19 '14 at 22:41
  • @Bordaigorl oh these days you could probably make a list of a few thousand 1-paragraph items and sort them using TeX, but... – David Carlisle May 20 '14 at 0:40
  • @DavidCarlisle Well, I indicated that I need sorting: Furthermore I want the notes to be sorted in a way that the lowest page numbers are at the beginning of the document and the larger page numbers further down. I know that it is easy to sort the notes in the Editor, but I asked if there is a possibility to let Latex sort my notes. Nevertheless, I am very glad at your answer! Do you know how to let Latex sort my notes (they can be one page long and contain bold text and formulas)? I am using Windows. – user50224 May 20 '14 at 8:21
2

First I would recommend you use a custom macro to hold your notes so that if you change your mind on their presentation you can implement the change by just changing the definition of your macro.

So let's call your macro \booknote{pageno}{text}.

I'll give you a very simple solution for the sorting part. If you are planning of taking only few notes it could make sense to have TeX sort them for you. Some more experienced user can give you advice on that. Instead, if you are taking a lot of notes it would make sense, for efficiency, to defer the sorting process to an external tool. This is what BibTeX does for example.
Now, we do not want to write a custom script and we do not need to! If you are on a Linux-ish OS you already have the program sort available at the console. It sorts the lines of a file in some order.
Now it is just a matter of organising your files:

  • the main file main.tex:

    \documentclass{article}
    \title{My notes for Bla}
    \author{myself}
    \newcommand{\booknote}[2]{\item[Pag.~#1] #2}
    \begin{document}
        \begin{description}
            \input{notes.tex}
        \end{description}
    \end{document}
    
  • the file holding your notes notes.tex:

    \booknote{45}{My note}
    \booknote{925}{another note}
    

Now since notes.tex has your notes one for each line we can sort the file with

sort -g -k 1.11 -t} -o notes.tex notes.tex
  • -g sorts numerically
  • -k 1.11 uses the first field as sorting key, and the key itself starts at the 11th character
  • -t} says that } is our field separator

So sort will see a line like \booknote{45}{My note} find the } thus seeing three fields \booknote{45, {My note and ``. It will pick the first, skip 10 chars obtaining 45 and use that as the key to sort the notes.

The drawbacks are: you cannot hard-wrap the text of the notes, you should not insert whitespace before \booknote although empty lines are allowed.

Every time you change notes.tex remember to invoke sort before you compile main.tex. Another option is using mynotes.tex to store the notes in the order you want and notes.tex as the target of sort so you can also edit your notes in the order you prefer.

  • Thanks, but I'm using Windows so I can't use sort.... – user50224 May 20 '14 at 8:14
  • 1
    @user50224 ah that's not my fault ;-P I had a look at the sort command windows offers but it does not seem to be powerful enough to sort numerically...I think @Gonzalo's solution is nice and cross-platform – Bordaigorl May 20 '14 at 10:12

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.