4

I am exporting a block of code

#+begin_lstlisting
cut -d \' | grep http://
#+end_lstlisting

But the org export to latex replaces the backslash with $\backslash$ and the http:// string with \url{http://}.

I have tried the export options

#+OPTIONS: ^:nil -:nil tex:verbatim

But they haven't done the trick. Any suggestions would be helpful.

I am using orgmode 8.2.10 on Emacs 25.1.50.2

Dan
  • 32,584
  • 6
  • 98
  • 168
Jesse
  • 267
  • 3
  • 10

1 Answers1

4

Use a combination of org code blocks and noweb to get the results you expected.

  1. Create a empty org code block for shell command C-c C-v d org

    #+BEGIN_SRC org
    #+END_SRC
    
  2. Assign a #+NAME: to block then add :results latex replace :exports none headers.

    #+NAME: latex-shell-script
    #+BEGIN_SRC org :results latex replace :exports none
    #+END_SRC
    
  3. Add an empty line into org block and place cursor on empty line.

    #+NAME: latex-shell-script
    #+BEGIN_SRC org :results latex replace :exports none
    _
    #+END_SRC
    
  4. Open empty org code block for editing using C-c ' then create sh code block

    #+BEGIN_SRC sh
      cut -d \' | grep http://
    #+END_SRC
    
  5. Save edited code with C-x C-s then close edit buffer with C-c '

    #+NAME: latex-shell-script
    #+BEGIN_SRC org :results latex replace :exports none
      ,#+BEGIN_SRC sh
      cut -d \' | grep http://
     ,#+END_SRC
    #+END_SRC
    
  6. Create a empty org code block for 1stlisting block C-c C-v d org

    #+BEGIN_SRC org
    #+END_SRC
    
  7. Add :noweb yes :results latex replace :exports results headers to empty block

    #+BEGIN_SRC org :noweb yes :results latex replace  :exports results 
    #+END_SRC
    
  8. Add an empty line into org block and place cursor on empty line.

    #+BEGIN_SRC org :noweb yes :results latex replace  :exports results 
    _
    #+END_SRC
    
  9. Open empty org code block for editing using C-c ' then enter the following code.

    #+begin_lstlisting
    <<latex-shell-script()>>
    #+end_lstlisting
    
  10. Save edited code with C-x C-s then close edit buffer with C-c '

    #+BEGIN_SRC org :noweb yes :results latex replace  :exports results 
      ,#+begin_lstlisting
      <<latex-shell-script()>>
      ,#+end_lstlisting
    #+END_SRC
    
  11. Use C-c C-e to export your code blocks to latex and you should see results similar to code listed below.

    \begin{lstlisting}
    \begin{verbatim}
    cut -d \' | grep http://
    \end{verbatim}
    \end{lstlisting}
    

Hope that helped!


Code Tested using

GNU Emacs 24.5.1 (x86_64-unknown-cygwin, GTK+ Version 3.14.13)
org-version: 8.3.2

Melioratus
  • 4,504
  • 1
  • 25
  • 43
  • Thank you for your answer! I tried running this and I got a "No org-babel-execute function for org!". I tried adding this (org-babel-do-load-languages 'org-bable-load-languages '((org . t))) but I still got the issue. Is there something else you configured? – Jesse Mar 04 '16 at 16:10
  • @Jesse - Oh no! I'm sure this just a configuration issue because I've been able to do this using earlier versions of org-mode. Did you type in new config by hand or did you use the customization menu? Could it be a typo? Another alternative *might* be that this setting is read at startup so restarting emacs will refresh it. I doubt this is the case though. Please let me know if this helped. – Melioratus Mar 04 '16 at 16:35
  • I found one problem of mine, I had `org-bable-load-languages instead of `org-babel-load-languages. After that when I run the latex export I am asked twice if I want to "Evaluate this org code block (latex-shell-script) on your system?". I answer yes both times and then I am asked if I want to "Evaluate this org code block on your system?", to which I answer yes. Then I get "Wrong type argument: listp, #("Jesse Millwood" 0 14 (:parent (#0)))". I assume this corresponds to my "#+AUTHOR: Jesse Millwood" line. I have never had an issue with this before. Do you have any suggestions? – Jesse Mar 07 '16 at 17:48
  • Actually after updating my org package by this [link](http://emacs.stackexchange.com/questions/14763/exporting-org-file-breaks-when-upgrading-to-orgmode-8-3) Everything worked fine. Thank you so much for your answer and follow up comments! – Jesse Mar 07 '16 at 18:03
  • Sorry, actually it ran, but the output is a bit odd. I have #+NAME: latex-shell-script #+BEGIN_SRC org :results latex replace ,#+BEGIN_SRC sh cut -d \' | grep http:// ,#+END_SRC #+END_SRC #+BEGIN_SRC org :noweb yes :results latex replace :exports results ,#+begin_lstlisting <> ,#+end_lstlisting #+END_SRC But it outputs: \begin{verbatim} #+BEGIN_SRC sh cut -d \' | grep http:// #+END_SRC \end{verbatim} \begin{lstlisting} \begin{verbatim} cut -d \' | grep http:// \end{verbatim} \end{lstlisting} – Jesse Mar 07 '16 at 18:12
  • @Jesse - Sorry my mistake! First code org block is missing ` :exports none` header. I'll update the instructions! Thanks for catching my error! – Melioratus Mar 07 '16 at 18:51
  • @Jesse - I updated instructions in my answer. Please let me know if that fixed your issue. It should. – Melioratus Mar 07 '16 at 18:55
  • That gives the output you said it would, Thank you! I think now I am having an issue with the `lstlisting` environment, as it is showing the `verbatim` environment on pdf export but that is, I believe, an issue with the latex environment and not orgmode. – Jesse Mar 07 '16 at 18:57