jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.36k stars 243 forks source link

Glossary and Acronym Tables are not being removed at export #1023

Closed fiatisdead closed 2 years ago

fiatisdead commented 2 years ago

OS: Windows 10 Emacs Version: 28.1 (Org-Version) 9.5.4

Steps to Reproduce:

  1. Git Clone this repo
  2. Open org-ref-master/melpa/init-melpa.el
  3. Evaluate Buffer
  4. test-1.org loads at the end of setting up the sandbox
  5. I can clearly see the GLS entries and acronym entries and the tables in the org buffer.
  6. C-c C-e l o (export to pdf and open)
  7. Contents of the PDF are not what I was expecting. The tables are present and there is no glossary or acronyms added to the end of the document as expected.

I fully expect this to be a user error as I have recently had to start over my setup on Windows10. I'm probably missing something.

This is the Output test-1.pdf

I had previously tried with a MWE org file to test glossary and acronym which failed with:

(c:/texlive/2022/texmf-dist/tex/latex/amsfonts/umsb.fd) (./glossaryMWE.toc)

! Package glossaries Error: Glossary entry `tree' has not been defined.

See the glossaries package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.43 Checkout how a \gls{tree} 
                               differs from a \gls{shrub}.
? 
! Emergency stop.
 ...                                              

l.43 Checkout how a \gls{tree} 
                               differs from a \gls{shrub}.
!  ==> Fatal error occurred, no output PDF file produced!

I then decided to download your current github repo and try the sandbox

I attach the MWE below incase it is useful.

#+title: Test
#+latex_header: \usepackage{glossaries}
#+latex_header: \makeglossaries
 #+DATE: \today
  #+AUTHOR: Author Redacted,\thanks{Correspondence:redacted@redacted.com}
  #+LANGUAGE: en
  #+SELECT_TAGS: export
  #+EXCLUDE_TAGS: noexport
  #+CREATOR: Emacs 28.1 (Org mode 9.5.4)

# This will not show in your export. It must be named glossary
#+name: glossary
| label | name  | description   |
|-------+-------+---------------|
| tree  | Tree  | A woody plant |
| shrub | Shrub | A woody bush  |

Checkout how a gls:tree differs from a gls:shrub.

#+name: acronyms
| Key  | Short | Long                           |
|------+-------+--------------------------------|
| mimo |       | multiple-input multiple output |
| qos  | QoS   | quality-of-service             |
| bb   | BB    | branch and bound               |

First ac:bb. Second ac:bb. First ac:qos. Second ac:qos.

# This is where your glossary and acronym entries will be put.
#+latex: \printglossaries
\glsaddall \printglossaries
jkitchin commented 2 years ago

You need to build it like this:

#+BEGIN_SRC emacs-lisp
(let ((org-export-before-parsing-hook '(org-ref-glossary-before-parsing org-ref-acronyms-before-parsing)))
  (org-open-file (org-latex-export-to-pdf)))
#+END_SRC

also, First ac:bb. Second ac:bb. First ac:qos. Second ac:qos. are not acronym links anymore:

(defvar org-ref-acronym-types
  '(("acrshort" "The acronym for label")
    ("acrshortpl" "The acronym for label in plural")
    ("Acrshort" "Capitalized acronym")
    ("Acrshortpl" "Plural capitalized acronym")
    ("ACRshort" "ALL-CAPS acronym")
    ("ACRshortpl" "ALL-CAPS plural acronym")

    ("acrlong" "The label definition")
    ("acrlongpl" "The plural definition")
    ("Acrlong" "Capitalized definition")
    ("Acrlongpl" "Plural capitalized definition")
    ("ACRlong" "ALL-CAPS definition")
    ("ACRlongpl" "plural ALL-CAPS definition")

    ("acrfull" "Both the acronym and its definition")
    ("acrfullpl" "Both the acronym and its definition in plural")
    ("Acrfull" "Capitalized both the acronym and its definition")
    ("Acrfullpl" "Capitalized both the acronym and its definition in plural")
    ("ACRfull" "Both the acronym and its definition in ALL-CAPS")
    ("ACRfullpl" "Both the acronym and its definition in plurall ALL-CAPS"))
  "list of acronym types (type description)")

I guess you could make them links if you add them to that list though.

fiatisdead commented 2 years ago

Thanks John for your reply. Its really appreciated. My knowledge of emacs is pretty limited tbh and so this is somewhat confusing for me. In Emacs 26.3 and Org-Mode 9.1.14 this used to just work out of the box. I'm assuming from the above things are no longer so simple?

ie. I could just add two org tables in my org file, one named glossary and one named acronym towards the end of the document and then I would simply add to the document the following properties prior to exporting to pdf.

+LATEX_HEADER: \usepackage[acronym]{glossaries}

+LATEX_HEADER: \makeglossaries

and add \printglossaries before \printbibliography and it just worked on export (C-c C-e l o)

(When I say worked it produced a Glossary Page with the entries from the table and a list of acronyms under the heading Acronyms. I am wondering if there was some kind of parsing hook in my original init.el file but having checked through previous configs I cannot for the life of me figure out what is going on or indeed why this no longer works as it did.

I tried to evaluate that the above source code and whilst it did not export the tables this time it did not produce a Glossary or any list of Acronyms on the test file.

I attempt to show you the full example as below.

#+latex_header: \usepackage{glossaries}
#+latex_header: \makeglossaries
# #+LATEX_HEADER: \usepackage[colorlinks=true,breaklinks]{hyperref} 

Acronym entries: [[gls:lvm][LVM]] and another one [[gls:lvm][LVM]] and one more ac:tla

gls:son   

A  [[gls:computer][computer]] is good  for computing. Gls:computer is capitalized. We can also use a bunch of glspl:computer to make a cluster. Glspl:computer a re the wave of the future. They do not use up any glspl:tree.

(or-next-glossary-link nil)

 [[gls:tree][tree]]            fjdsa;fdsa

Labels and refs: label:one

label:two   ref:two

 Multiply defined label:one

#+BEGIN_SRC emacs-lisp
(let ((org-export-before-parsing-hook '(org-ref-glossary-before-parsing org-ref-acronyms-before-parsing)))
  (org-open-file (org-latex-export-to-pdf)))
#+END_SRC

#+RESULTS:

bibliography:test-1.bib

#+name: acronyms
| label | abbreviation | full form            |
|-------+--------------+----------------------|
| tla   | TLA          | three letter acronym |
| qos   | QoS          | Quality-of-Service   |

#+name: glossary
| label    | term     | definition             |
|----------+----------+------------------------|
| test     | test     | a test                 |
| son      | son      | male                   |
| naive    | naive    | lacking sophisticatio  |
| tree     | tree     | a big, woody plant     |
| computer | computer | a digital machine      |
| lvm      | LVM      | logical volume manager |

[[printglossaries:]]

When I evaluate the source block you provided I get the following result: test-2.pdf

You will see that it is pulling through the glossary and acronyms. I have realised your point above ac: no longer works i need to use acrshort: or acrfull: - understood. But the Output Glossary Index and Output Acronym Index at the back of the document are still missing. I'm unsure how to remedy this.

I make a further explanatory comment to state that I have removed the default hyperref from org-latex-default-packages-alist

 '(org-latex-default-packages-alist
   '(("AUTO" "inputenc" t
      ("pdflatex"))
     ("T1" "fontenc" t
      ("pdflatex"))
     ("" "graphicx" t nil)
     ("" "longtable" nil nil)
     ("" "wrapfig" nil nil)
     ("" "rotating" nil nil)
     ("normalem" "ulem" t nil)
     ("" "amsmath" t nil)
     ("" "amssymb" t nil)
     ("" "capt-of" nil nil)
     )))

and I have commented out the adding back in of the hyperef package as you will not need that (but I do) for testing the example, This is mandatory for me to do on every org file as the early call of hyperref as default causes conflicts with the way I use Oscola-Biblatex packages which is the primary reason I use emacs.

fiatisdead commented 2 years ago

I attach an example pdf of what the output used to look like when I exported using C-c C-e l o example.pdf

Having rechecked my init.org / init.el files - I cannot see any pre-parse hooks that I used to call. Put simply all I did was put the two org tables in the org file and run the standard org-export to pdf using the default keybinding C-c C-e l o

This gave me the output in example.pdf above.

jkitchin commented 2 years ago

I guess you are not running this correctly.

Put a section like this at the end:

* build                                                            :noexport:

#+BEGIN_SRC emacs-lisp
(let ((org-export-before-parsing-hook '(org-ref-glossary-before-parsing org-ref-acronyms-before-parsing)))
  (org-open-file (org-latex-export-to-pdf)))
#+END_SRC

Then execute that emacs-lisp block with C-c C-c

If you want C-c C-e lo to work like before, you need to add this to your init file:

(setq org-export-before-parsing-hook '(org-ref-glossary-before-parsing org-ref-acronyms-before-parsing))

This is different in version 3 than it was in version 2.

fiatisdead commented 2 years ago

Again, I really appreciate your help here. I appreciate that as you will see from the below that this appears not to be an issue with org-ref as demonstrated below. Any pointers I would be very grateful.

Put a section like this at the end:


* build                                                            :noexport:

+BEGIN_SRC emacs-lisp

(let ((org-export-before-parsing-hook '(org-ref-glossary-before-parsing org-ref-acronyms-before-parsing))) (org-open-file (org-latex-export-to-pdf)))

+END_SRC


> Then execute that emacs-lisp block with C-c C-c

It brings through the acronyms and the glossary terms into the PDF but still is not printing the glossary or index. 

Org-file: 
[test-2.org.zip](https://github.com/jkitchin/org-ref/files/9097187/test-2.org.zip)

Tex-file:(compiled from running the above)
[test-2.tex.zip](https://github.com/jkitchin/org-ref/files/9097190/test-2.tex.zip)

pdf: 
[test-2.pdf](https://github.com/jkitchin/org-ref/files/9097192/test-2.pdf)

I am really at a loss as to what is going on. I have tried stripping down almost all of my config and even tried to use your sandbox from the github using your init files from github source and still no joy. 

The issue I think is with Latex or pdflatex as I think the .tex looks right as it  is correctly parsing the acronym and glossary entries into the tex file and has /printglossaries before /printbibliography which should work right?

I wonder if you would mind testing the .tex file and see if you run pdflatex are you seeing the glossary and acronym printed before the bibliogrpahy or just the same three page pdf? 

This I guess will prove the issue to be outside of org-ref I think but I haven't the first clue as to what is going on here. Something that worked previously so simple is literally now driving me crazy. :)

Thank you in advance with this,
The above files are compressed as .zip because github does not permit .org or .tex files to be uploaded.
fiatisdead commented 2 years ago

Ok, I've figured out a work-around. I never had to do this previously as I said C-c C-e l o just worked out the box.

  1. Once emacs has outputted the .org and .tex and .pdf
  2. Open .tex in Tex-Studio
  3. Run Latex
  4. Run Biber
  5. Run Latex
  6. Run MakeGlossaries
  7. Run Latex
  8. Run Pdflatex

It now makes and prints the glossary.

Unsure why this is now necessary as it never used to be on previous versions. Any way to remove this manual intervention and have orgmode export to pdf without the requirement of the manual work-around would be super helpful. I'd happily donate to a charity of your choosing or your work.

jkitchin commented 2 years ago

(this response was in preparation when I saw your additional comment above).

It could be related to building the pdf. Somewhere you need to get makeglossaries to run. I do this by using ox-manuscript-latex-pdf-process which is what org-latex-pdf-process is set to.

or, see https://github.com/jkitchin/org-ref/blob/master/org-ref.org#latex-export and adapt it like this:

(setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
    "bibtex %b"
        "makeglossaries %b"
    "pdflatex -interaction nonstopmode -output-directory %o %f"
    "pdflatex -interaction nonstopmode -output-directory %o %f"))

I think that should do it.

It seems tricky to get latexmk to do this correctly, but it is probably also possible.

fiatisdead commented 2 years ago

Thank you again for your help. Much appreciated. Sadly changing from my latexmk in the init to the suggestion above breaks my citations. I get a list of citekeys as footnotes instead of the properly formatted citations being rendered.

I will stick with the manual work-around as I have to manually process makeglossaries to do the table of contents and index of legal cases and statutes so this is no hardship for the final pdf and the links are working in the org-file so its no big deal.

Happy to donate to your work so send me a link. Thanks again and huge respect for all you do. Peace. Once done you can close this.

jkitchin commented 2 years ago

You should probably change bibtex to biber then. The list of commands should match what you do at the command line.

fiatisdead commented 2 years ago

You should probably change bibtex to biber then. The list of commands should match what you do at the command line.

Wow, Thank you.

   (setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
        "biber %b"
        "makeglossaries %b"
        "pdflatex -interaction nonstopmode -output-directory %o %f"
        "pdflatex -interaction nonstopmode -output-directory %o %f"
        "splitindex %b -s oscola"
        "pdflatex -interaction nonstopmode -output-directory %o %f"))

This works better than ever and now means I no longer have to manually post-process TOC index front matter of cases/statutes. C-c C-e l o and we are done.

:) I will sort github sponsor in a few days. Thanks.

fiatisdead commented 2 years ago

Summary Solution

Original Issue of Glossary and Acronym Tables not being removed at export was resolved by adding the below to init.el

(setq org-export-before-parsing-hook '(org-ref-glossary-before-parsing org-ref-acronyms-before-parsing))

This then morphed into a second issue where the \PrintGlossaries were not automatically making and rendering in the pdf output. Having reviewed the LaTeX document I could see the issue was not with org-ref but the pdf build process.

For total clarity I have never previously needed to have a "makeglossaries %b" in the emacs init.el file. In order for \printglossaries to output into the pdf - Now it appears necessary.

Thank you to @jkitchin for all the help here.

To fix the pdf build issue and print the glossaries we changed the org-latex-pdf-process in my init.el to

 (setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
        "biber %b"
        "makeglossaries %b"
        "pdflatex -interaction nonstopmode -output-directory %o %f"
        "pdflatex -interaction nonstopmode -output-directory %o %f"
        "splitindex %b -s oscola"
        "pdflatex -interaction nonstopmode -output-directory %o %f"))
jkitchin commented 2 years ago

Thanks for the summary solution!