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

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

  • 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 4 '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 4 '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 7 '16 at 17:48
  • Actually after updating my org package by this link Everything worked fine. Thank you so much for your answer and follow up comments! – Jesse Mar 7 '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 <<latex-shell-script()>> ,#+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 7 '16 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.