5
votes

I have a set of tables in org-mode that I am exporting, but I'd like certain columns used for calculations and consumption by code blocks to be excluded from LaTeX export.

I'm sure I saw a way to do this by specifying a range of columns to export below the table, but I can't find reference to it anywhere on the web so there's a good chance I dreamt it.

5

5 Answers

6
votes

Another way to achieve this is by defining a "hidden" column type H in the LaTeX header options of the org file and then use #+ATTR_LATEX: :align llH to indicate that the third column is to be hidden on export (source):

#+LATEX_HEADER: \usepackage{array}
#+LATEX_HEADER: \newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

#+ATTR_LATEX: :align llH
|-----+-------+------|
|   2 | 1/2   | junk |
|   4 | 1/4   | junk |
|   8 | 1/2   | junk |
3
votes

If you are using "Radio Tables" you can do something like

#+ORGTBL: SEND some-name orgtbl-to-latex :skipcols (3)
|-----+-------+------|
|   2 | 1/2   | junk |
|   4 | 1/4   | junk |
|   8 | 1/2   | junk |

See http://www.gnu.org/software/emacs/manual/html_mono/org.html#Radio-tables for all the details.

I believe it may not be possible directly with export via C-c C-e since they offer the same answer at http://comments.gmane.org/gmane.emacs.orgmode/33946 from November 2010.

1
votes

I use Michael Brand's solution proposed here and cataloged by Derek Feichtinger here (make sure to view the file in raw mode, otherwise the source is hidden by GitHub).

For convenience, I reproduce the code below:

* Exporting tables with some columns hidden

  It is desirable to be able and hide columns in exported output. This is often the
  case in tables where a lot of computations are done, and where intermediate
  results end up in columns that one does not want to end up in the exported document.

  This functionality is currently not available by standard org, but since this is Emacs, a simple function
  implementing this functionality was published by [[https://github.com/brandm][Michael Brand]] within this [[http://lists.gnu.org/archive/html/emacs-orgmode/2016-05/msg00027.html][emacs-orgmode thread]].

  #+BEGIN_SRC emacs-lisp :results silent :exports source
    (defun dfeich/org-export-delete-commented-cols (back-end)
      "Delete columns $2 to $> marked as `<#>' on a row with `/' in $1.
    If you want a non-empty column $1 to be deleted make it $2 by
    inserting an empty column before and adding `/' in $1."
      (while (re-search-forward "^[ \t]*| +/ +|\\(.*|\\)? +\\(<#>\\) *|" nil t)
    (goto-char (match-beginning 2))
    (org-table-delete-column)
    (beginning-of-line)))
    (add-hook 'org-export-before-processing-hook #'dfeich/org-export-delete-commented-cols)
    ;; (remove-hook 'org-export-before-processing-hook #'dfeich/org-export-delete-commented-cols)
  #+END_SRC  

  The exported table will have col2 removed.

  |   | col1 | col2 | col3 |
  | / |  <r> | <#>  |      |
  |   |   a1 | a2   | a3   |
  |   |   b1 | b2   | b3   |
0
votes

http://www.gnu.org/software/emacs/manual/html_mono/org.html#The-spreadsheet

3.5.6 Editing and debugging formulas Use ‘/’ for: Do not export this line. Useful for lines that contain the narrowing ‘’ markers or column group markers.

Note to do this you must use the first column for extra info to do this.

0
votes

I've found that the most convenient way is to:

  1. make the table not exportable with :noexport: tag,
  2. select the columns I want to be exported with source block, using elisp, and make the result exportable.

Here is an example with elisp.

* Hidden :noexport:
#+NAME: google
| file      | total | other | p  |
|-----------+-------+-------+----|
| de-01.pdf |   312 |    76 | 76 |
| de-02.pdf |   428 |   101 | 77 |
| de-03.pdf |  1069 |   217 | 80 |

* Exported
Here it comes.

#+begin_src elisp :var data=google :colnames yes
;; select 0th and 3rd column from a table accessible with 'google' name
;; and do some math on it
  (mapcar (lambda (e) (list (nth 0 e) (nth 3 e))) data)
#+end_src

#+RESULTS:
| file      | p  |
|-----------+----|
| de-01.pdf | 76 |
| de-02.pdf | 77 |
| de-03.pdf | 80 |

You can also use any other language that is supported by the source blocks to loop over the results and produce desired output.