emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Is it possible to repeat a block of org-mode text on export, maybe with replacement?
@ 2013-11-19 13:47 Gary Oberbrunner
  2013-11-19 16:13 ` Thorsten Jolitz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Gary Oberbrunner @ 2013-11-19 13:47 UTC (permalink / raw)
  To: Orgmode Mailing List

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

I don't know if this is beyond the capabilities of org-mode or not.  I'd
like to have a block of text repeated multiple times with slight
variations.  For the sake of the example, a numbered list:

1. this is the first line
1. this is the second line with %VARIANT% as the value
1. this is the third line

When exported, say as ASCII, I'd like this:

1. this is the first line
2. this is the second line with foo as the value
3. this is the third line

1. this is the first line
2. this is the second line with bar as the value
3. this is the third line

1. this is the first line
2. this is the second line with baz as the value
3. this is the third line

I'm not sure how to go about this; I assume I'd use org-babel with source
blocks that contain org-mode text or elisp or something.

Of course if the right answer is I should write a python script to generate
my org-mode text, well, that's OK too. :-)

-- 
Gary

[-- Attachment #2: Type: text/html, Size: 1348 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is it possible to repeat a block of org-mode text on export, maybe with replacement?
  2013-11-19 13:47 Is it possible to repeat a block of org-mode text on export, maybe with replacement? Gary Oberbrunner
@ 2013-11-19 16:13 ` Thorsten Jolitz
  2013-11-19 16:36 ` Eric Schulte
  2013-11-19 17:19 ` Thomas S. Dye
  2 siblings, 0 replies; 5+ messages in thread
From: Thorsten Jolitz @ 2013-11-19 16:13 UTC (permalink / raw)
  To: emacs-orgmode

Gary Oberbrunner <garyo@oberbrunner.com> writes:

> I don't know if this is beyond the capabilities of org-mode or not.
>  I'd like to have a block of text repeated multiple times with slight
> variations.  For the sake of the example, a numbered list:
>
> 1. this is the first line
> 1. this is the second line with %VARIANT% as the value
> 1. this is the third line
>
> When exported, say as ASCII, I'd like this:
>
> 1. this is the first line
> 2. this is the second line with foo as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with bar as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with baz as the value
> 3. this is the third line
>
> I'm not sure how to go about this; I assume I'd use org-babel with
> source blocks that contain org-mode text or elisp or something.
>
> Of course if the right answer is I should write a python script to
> generate my org-mode text, well, that's OK too. :-)

Maybe something like this?

#+header: :var lst='("foo" "bar" "baz")
#+begin_src emacs-lisp :results raw value :exports results
  (mapconcat
   (lambda (--elem)
     (format 
      (concat
       "1. this is The first line\n"
       "2. this is the second line with %s as the value\n"
       "3. this is the third line\n")
      --elem))
   lst "\n")
#+end_src

#+results:
1. this is The first line
2. this is the second line with foo as the value
3. this is the third line

1. this is The first line
2. this is the second line with bar as the value
3. this is the third line

1. this is The first line
2. this is the second line with baz as the value
3. this is the third line

#+begin_src emacs-lisp :exports none :results raw 
  (org-export-as 'ascii)
#+end_src

#+results:
                           _________________

                                  506

                            Thorsten Jolitz
                           _________________


Table of Contents
_________________

1 --text follows this line--


1 --text follows this line--
============================

  Gary Oberbrunner <garyo@oberbrunner.com> writes:

  > I don't know if this is beyond the capabilities of org-mode or not.
  >  I'd like to have a block of text repeated multiple times with
  > slight variations.  For the sake of the example, a numbered list: 1.
  > this is the first line 1. this is the second line with %VARIANT% as
  > the value 1. this is the third line When exported, say as ASCII, I'd
  > like this: 1. this is the first line 2. this is the second line with
  > foo as the value 3. this is the third line 1. this is the first line
  > 2. this is the second line with bar as the value 3. this is the
  > third line 1. this is the first line 2. this is the second line with
  > baz as the value 3. this is the third line I'm not sure how to go
  > about this; I assume I'd use org-babel with source blocks that
  > contain org-mode text or elisp or something. Of course if the right
  > answer is I should write a python script to generate my org-mode
  > text, well, that's OK too. :-)

  Maybe something like this?

  1. this is The first line
  2. this is the second line with foo as the value
  3. this is the third line

  4. this is The first line
  5. this is the second line with bar as the value
  6. this is the third line

  7. this is The first line
  8. this is the second line with baz as the value
  9. this is the third line

  -- cheers, Thorsten

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is it possible to repeat a block of org-mode text on export, maybe with replacement?
  2013-11-19 13:47 Is it possible to repeat a block of org-mode text on export, maybe with replacement? Gary Oberbrunner
  2013-11-19 16:13 ` Thorsten Jolitz
@ 2013-11-19 16:36 ` Eric Schulte
  2013-11-19 17:19 ` Thomas S. Dye
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2013-11-19 16:36 UTC (permalink / raw)
  To: Gary Oberbrunner; +Cc: Orgmode Mailing List

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

Gary Oberbrunner <garyo@oberbrunner.com> writes:

> I don't know if this is beyond the capabilities of org-mode or not.  I'd
> like to have a block of text repeated multiple times with slight
> variations.  For the sake of the example, a numbered list:
>
> 1. this is the first line
> 1. this is the second line with %VARIANT% as the value
> 1. this is the third line
>
> When exported, say as ASCII, I'd like this:
>
> 1. this is the first line
> 2. this is the second line with foo as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with bar as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with baz as the value
> 3. this is the third line
>
> I'm not sure how to go about this; I assume I'd use org-babel with source
> blocks that contain org-mode text or elisp or something.
>

The following Org-mode file.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: repeater.org --]
[-- Type: text/x-org, Size: 804 bytes --]

#+Title: Example demonstrating repetition of a block of text

* Top

When exported, say as ASCII, I'd like this:

#+call: w/replacement(replacement="foo") :results list
#+call: w/replacement(replacement="bar") :results list
#+call: w/replacement(replacement="baz") :results list

* COMMENT Support

#+name: lines
1. this is the first line
2. this is the second line with %VARIANT% as the value
3. this is the third line

#+name: w/replacement
#+begin_src emacs-lisp :var lines=lines :var replacement="rep" :results list
  (mapcar (lambda (line)
            (replace-regexp-in-string
             (regexp-quote "%VARIANT%") replacement line 'fixedcase))
          lines)
#+end_src

#+RESULTS: w/replacement
- this is the first line
- this is the second line with rep as the value
- this is the third line

[-- Attachment #3: Type: text/plain, Size: 33 bytes --]


exports to the following ASCII


[-- Attachment #4: repeater.txt --]
[-- Type: text/plain, Size: 648 bytes --]

           __________________________________________________

             EXAMPLE DEMONSTRATING REPETITION OF A BLOCK OF
                                  TEXT
           __________________________________________________


Table of Contents
_________________

1 Top





1 Top
=====

  When exported, say as ASCII, I'd like this:

  - this is the first line
  - this is the second line with foo as the value
  - this is the third line

  - this is the first line
  - this is the second line with bar as the value
  - this is the third line

  - this is the first line
  - this is the second line with baz as the value
  - this is the third line

[-- Attachment #5: Type: text/plain, Size: 198 bytes --]


Cheers,

>
> Of course if the right answer is I should write a python script to generate
> my org-mode text, well, that's OK too. :-)

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is it possible to repeat a block of org-mode text on export, maybe with replacement?
  2013-11-19 13:47 Is it possible to repeat a block of org-mode text on export, maybe with replacement? Gary Oberbrunner
  2013-11-19 16:13 ` Thorsten Jolitz
  2013-11-19 16:36 ` Eric Schulte
@ 2013-11-19 17:19 ` Thomas S. Dye
  2013-11-21 23:23   ` Gary Oberbrunner
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2013-11-19 17:19 UTC (permalink / raw)
  To: Gary Oberbrunner; +Cc: Orgmode Mailing List

Hi Gary,

I came up with this, which uses example blocks.

#+name: example
#+begin_example
 1. this is the first line
 2. this is the second line with %VARIANT% as the value
 3. this is the third line
#+end_example

#+name: repeated-text
#+header: :results raw
#+header: :var x="" 
#+header: :var eg=example
#+begin_src emacs-lisp
  (let ((result))
    (setf result (replace-regexp-in-string "%VARIANT%" x eg t))
    result)
#+end_src

#+call: repeated-text(x="foo") :results raw

#+results:
1. this is the first line
 2. this is the second line with foo as the value
 3. this is the third line

#+call: repeated-text(x="bar") :results raw
#+results:
1. this is the first line
 2. this is the second line with bar as the value
 3. this is the third line

#+call: repeated-text(x="baz") :results raw

#+results:
1. this is the first line
 2. this is the second line with baz as the value
 3. this is the third line

All the best,
Tom

Gary Oberbrunner <garyo@oberbrunner.com> writes:

> I don't know if this is beyond the capabilities of org-mode or not.  I'd
> like to have a block of text repeated multiple times with slight
> variations.  For the sake of the example, a numbered list:
>
> 1. this is the first line
> 1. this is the second line with %VARIANT% as the value
> 1. this is the third line
>
> When exported, say as ASCII, I'd like this:
>
> 1. this is the first line
> 2. this is the second line with foo as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with bar as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with baz as the value
> 3. this is the third line
>
> I'm not sure how to go about this; I assume I'd use org-babel with source
> blocks that contain org-mode text or elisp or something.
>
> Of course if the right answer is I should write a python script to generate
> my org-mode text, well, that's OK too. :-)
>
> -- 
> Gary
> I don't know if this is beyond the capabilities of org-mode or not. I'd
> like to have a block of text repeated multiple times with slight
> variations. For the sake of the example, a numbered list:
>
> 1. this is the first line
> 1. this is the second line with %VARIANT% as the value
> 1. this is the third line
>
> When exported, say as ASCII, I'd like this:
>
> 1. this is the first line
> 2. this is the second line with foo as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with bar as the value
> 3. this is the third line
>
> 1. this is the first line
> 2. this is the second line with baz as the value
> 3. this is the third line
>
> I'm not sure how to go about this; I assume I'd use org-babel with
> source blocks that contain org-mode text or elisp or something.
>
> Of course if the right answer is I should write a python script to
> generate my org-mode text, well, that's OK too. :-)

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is it possible to repeat a block of org-mode text on export, maybe with replacement?
  2013-11-19 17:19 ` Thomas S. Dye
@ 2013-11-21 23:23   ` Gary Oberbrunner
  0 siblings, 0 replies; 5+ messages in thread
From: Gary Oberbrunner @ 2013-11-21 23:23 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Orgmode Mailing List

[-- Attachment #1: Type: text/plain, Size: 3705 bytes --]

Thanks everyone!  Much appreciated. I think I can get what I want by
fiddling with these.  Thomas, I'm not sure why but yours comes out with
weird indentation which makes the first line not part of the list.  Eric,
yours doesn't seem to create a proper numbered list at all, but is
otherwise just what I'm looking for.  Thorsten, yours comes out looking
great but having to Emacs-stringize the text is, well, you know...

Again thanks all for your helpful suggestions!


On Tue, Nov 19, 2013 at 12:19 PM, Thomas S. Dye <tsd@tsdye.com> wrote:

> Hi Gary,
>
> I came up with this, which uses example blocks.
>
> #+name: example
> #+begin_example
>  1. this is the first line
>  2. this is the second line with %VARIANT% as the value
>  3. this is the third line
> #+end_example
>
> #+name: repeated-text
> #+header: :results raw
> #+header: :var x=""
> #+header: :var eg=example
> #+begin_src emacs-lisp
>   (let ((result))
>     (setf result (replace-regexp-in-string "%VARIANT%" x eg t))
>     result)
> #+end_src
>
> #+call: repeated-text(x="foo") :results raw
>
> #+results:
> 1. this is the first line
>  2. this is the second line with foo as the value
>  3. this is the third line
>
> #+call: repeated-text(x="bar") :results raw
> #+results:
> 1. this is the first line
>  2. this is the second line with bar as the value
>  3. this is the third line
>
> #+call: repeated-text(x="baz") :results raw
>
> #+results:
> 1. this is the first line
>  2. this is the second line with baz as the value
>  3. this is the third line
>
> All the best,
> Tom
>
> Gary Oberbrunner <garyo@oberbrunner.com> writes:
>
> > I don't know if this is beyond the capabilities of org-mode or not.  I'd
> > like to have a block of text repeated multiple times with slight
> > variations.  For the sake of the example, a numbered list:
> >
> > 1. this is the first line
> > 1. this is the second line with %VARIANT% as the value
> > 1. this is the third line
> >
> > When exported, say as ASCII, I'd like this:
> >
> > 1. this is the first line
> > 2. this is the second line with foo as the value
> > 3. this is the third line
> >
> > 1. this is the first line
> > 2. this is the second line with bar as the value
> > 3. this is the third line
> >
> > 1. this is the first line
> > 2. this is the second line with baz as the value
> > 3. this is the third line
> >
> > I'm not sure how to go about this; I assume I'd use org-babel with source
> > blocks that contain org-mode text or elisp or something.
> >
> > Of course if the right answer is I should write a python script to
> generate
> > my org-mode text, well, that's OK too. :-)
> >
> > --
> > Gary
> > I don't know if this is beyond the capabilities of org-mode or not. I'd
> > like to have a block of text repeated multiple times with slight
> > variations. For the sake of the example, a numbered list:
> >
> > 1. this is the first line
> > 1. this is the second line with %VARIANT% as the value
> > 1. this is the third line
> >
> > When exported, say as ASCII, I'd like this:
> >
> > 1. this is the first line
> > 2. this is the second line with foo as the value
> > 3. this is the third line
> >
> > 1. this is the first line
> > 2. this is the second line with bar as the value
> > 3. this is the third line
> >
> > 1. this is the first line
> > 2. this is the second line with baz as the value
> > 3. this is the third line
> >
> > I'm not sure how to go about this; I assume I'd use org-babel with
> > source blocks that contain org-mode text or elisp or something.
> >
> > Of course if the right answer is I should write a python script to
> > generate my org-mode text, well, that's OK too. :-)
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>



-- 
Gary

[-- Attachment #2: Type: text/html, Size: 4981 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-21 23:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 13:47 Is it possible to repeat a block of org-mode text on export, maybe with replacement? Gary Oberbrunner
2013-11-19 16:13 ` Thorsten Jolitz
2013-11-19 16:36 ` Eric Schulte
2013-11-19 17:19 ` Thomas S. Dye
2013-11-21 23:23   ` Gary Oberbrunner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).