组织模式表:从导出中排除列

发布于 2024-11-19 16:43:00 字数 132 浏览 5 评论 0原文

我正在导出一组组织模式的表,但我希望将用于计算和代码块消耗的某些列从 LaTeX 导出中排除。

我确信我找到了一种方法,通过在表格下方指定要导出的一系列列来实现此目的,但我在网络上的任何地方都找不到对它的引用,所以很有可能是我梦到的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暖阳 2024-11-26 16:43:00

实现此目的的另一种方法是在 org 文件的 LaTeX 标头选项中定义“隐藏”列类型 H,然后使用 #+ATTR_LATEX: :align llH 来指示第三列在导出时隐藏(来源) :

#+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 |

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 |
醉生梦死 2024-11-26 16:43:00

如果您使用“Radio Tables”,您可以执行类似的操作

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

,请参阅 http://www.gnu.org/software/emacs/manual/html_mono/org.html#Radio-tables 了解所有详细信息。

我相信通过 Cc Ce 直接导出可能是不可能的,因为他们在 http://comments.gmane.org/gmane.emacs.orgmode/33946 从 2010 年 11 月开始。

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.

蛮可爱 2024-11-26 16:43:00

我使用 此处提出的 Michael Brand 解决方案德里克·费希廷格 (Derek Feichtinger) 编目 这里(确保以原始模式查看文件,否则源会被 GitHub 隐藏)。

为了方便起见,我复制了下面的代码:

* 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 
gt; 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   |

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 
gt; 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   |
樱花落人离去 2024-11-26 16:43:00

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

3.5.6 编辑和调试公式
使用 '/' 表示:不导出此行。对于包含缩小 '' 标记或列组标记的行很有用。

请注意,要执行此操作,您必须使用第一列来获取额外信息。

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.

萌面超妹 2024-11-26 16:43:00

我发现最方便的方法是:

  1. 使用 :noexport: 标记使表不可导出,
  2. 使用 elisp 选择我想要使用源块导出的列,并使结果可导出。

这是一个 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 |

您还可以使用源块支持的任何其他语言来循环结果并生成所需的输出。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文