0

I tried to do \n, but it did not work.

What string may I write in org-mode to create a new line?

For example, I wrote the following lines in literate programming:

#+begin_src clojure
     "test/ntest"
#+end_src

#+RESULTS:
: test/ntest

but the result is not doing new line.

6
  • If you mean export, you can leave a blank line in org file. Commented Jul 12, 2022 at 2:22
  • 1
    "... it did not work": that is a very common description of a problem and it is almost always completely useless. Say exactly what you want to accomplish, what you tried, what the result was. As you can see from the previous comment, it is not clear what you meant: are you talking about a newline in the Org mode buffer in Emacs? If so, just RET should work fine - Org mode files are text files. Are you talking about breaking a line when you export? @TianshuWang's comment may help. But in this case, you should also specify what you export to: HTML, PDF, ODT? Asking a good question ...
    – NickD
    Commented Jul 14, 2022 at 2:01
  • 1
    ... takes thought and practice. There are many good guides available on the web - e.g. How To Ask Questions The Smart Way. Read one or more before asking your next question: it will help you and it will help the people who are eager to answer your questions.
    – NickD
    Commented Jul 14, 2022 at 2:05
  • I update my question. Sorry for being that imprecise. @NickD
    – David
    Commented Jul 14, 2022 at 6:39
  • 2
    You have misspelled \n using a forward slash, rather than a backslash. I don't have clojure but the equivalent block in elisp works fine.
    – NickD
    Commented Jul 14, 2022 at 12:16

2 Answers 2

0

Most people just hit enter, just like in any other buffer. If that doesn’t work for you, then you should include more information about the problem.

2
  • I can't i just want to print a new line with literate programming.
    – David
    Commented Jul 13, 2022 at 17:25
  • 2
    If you are writing a program in a source block then you would use whatever syntax is ordinarily used by that programming language. You should include that information in you question too.
    – db48x
    Commented Jul 13, 2022 at 18:16
0

I installed Clojure 1.11.1 and had to modify the value of ob-clojure-cli-command to be just clojure1. With that change, I tried the following code blocks (shown with the results I get):


#+begin_src clojure :results value drawer
  "test\ntest"
#+end_src

#+RESULTS:
:results:
"test\ntest"
:end:

#+begin_src clojure :results value drawer
    "test
  test"
#+end_src

#+RESULTS:
:results:
"test\ntest"
:end:

#+begin_src clojure :results output drawer
  (print "test\ntest")
#+end_src

#+RESULTS:
:results:
test
test
:end:

Here are the results from a command line session of clojure:

$ clojure
Clojure 1.11.1
user=> "test\ntest"
"test\ntest"
user=> "test
test"
"test\ntest"
user=> (print "test\ntest")
test
testnil
user=> (print "test
test")
test
testnil
user=> 

They are entirely consistent2: clojure insists on the escaped form of the newline, whether you give the escaped form or a "real" newline in the string. It only produces a "real" newline (a LF/CR combination) if you print the string.

You will need to readjust your expectations.


[1] That is, instead of the apparent default clojure -M which was giving me java errors - full disclosure: I know very little about clojure and very little about java - you have been warned.

[2] The nil in the last two cases is the value that print returns - that is suppressed in babel when you use :results output. Only the output is printed. You would use :results value to print the returned value, but then you would not see the output. The REPL prints both the output and the returned value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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