Can I strip out id links in latex/pdf exports?

Is there a way to strip out org “id” links from an org file when exporting to latex/pdf? Ideally, I would love to be able to write a long-form document in org-roam and link relevant terms for myself, but then export this document to pdf/latex without these links.

2 Likes

Org-export has a pre-processing hook. I believe you can write a script to remove ID links there.

Don’t worry much about keeping your original notes buffer intact when you write such a script. Org-export copies the whole buffer into a temporary buffer — I think the pre-processor works on the copy not the original so you can be crude and ruthless about removing elements you don’t need for export (Of course, please test this on your end).

1 Like

:pray:

Thank you! That sounds like it will do the trick!

I was looking for a solution for this exact question. Have you made a solution/function that allows you to do this? Also, how did you handle the cases where the ids are links to “normal titles”/headings, and not nodes?

Unfortunately, @Cletip, I didn’t end up writing a function for this. I asked this after this project was completed and haven’t needed this functionality, since.

No problem, thanks anyway :slight_smile:

Here is mine (doom emacs config) :smile: :

(defun org-export-id-link-removal (backend)
  "Inspired by 'org-attach-expand-links' ,which is in 'org-export-before-parsing-functions' "
  (save-excursion
    (while (re-search-forward "id:" nil t)
      (let ((link (org-element-context)))
        (if (and (eq 'link (org-element-type link))
                 (string-equal "id"
                               (org-element-property :type link)))
            (let ((description (and (org-element-property :contents-begin link)
                                    (buffer-substring-no-properties
                                     (org-element-property :contents-begin link)
                                     (org-element-property :contents-end link))))
                  )
              (goto-char (org-element-property :end link))
              (skip-chars-backward " \t")
              (delete-region (org-element-property :begin link) (point))
              (insert description))
          )))))

(after! ox-latex
  (add-to-list 'org-export-before-parsing-functions #'org-export-id-link-removal)
  )

1 Like