【问题标题】:Org-mode tables: Exclude columns from export组织模式表:从导出中排除列
【发布时间】:2011-07-10 13:34:08
【问题描述】:

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

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

【问题讨论】:

    标签: emacs latex org-mode


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      如果您使用的是“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

      我认为通过C-c C-e 直接导出可能是不可能的,因为他们从 2010 年 11 月开始在http://comments.gmane.org/gmane.emacs.orgmode/33946 提供相同的答案。

      【讨论】:

      • 这似乎是目前唯一的方法,尽管它不适用于链接建议的导出。干杯。
      【解决方案3】:

      我使用 Michael Brand 提出的 here 并由 Derek Feichtinger here 编目的解决方案(确保以原始模式查看文件,否则源被 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 $> 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   |
      

      【讨论】:

        【解决方案4】:

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

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

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

        【讨论】:

        • 这允许您删除一行,但我需要删除一些列。不过还是谢谢。
        • 艰难!不确定这一点,因为我还在处理 Org 模式的电子表格。
        【解决方案5】:

        我发现最方便的方法是:

        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 |
        

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-05-24
          • 1970-01-01
          • 1970-01-01
          • 2012-01-21
          • 2016-08-14
          • 1970-01-01
          相关资源
          最近更新 更多