* [BUG] bug in 'ox-man?
@ 2022-01-31 14:00 Greg Minshall
2022-02-01 0:25 ` Greg Minshall
0 siblings, 1 reply; 5+ messages in thread
From: Greg Minshall @ 2022-01-31 14:00 UTC (permalink / raw)
To: emacs-orgmode
hi, all.
this works when exporting as a .pdf or a .html. but, not when
exporting to 'ox-man:
#+begin_src bash :results output :exports code :eval never-export
echo 'lf "\n"'
#+end_src
(the result has a "0" in it, appears to have gotten confused by maybe
trying to substitute a newline character for the backslash-n, ???)
i'm running:
Org mode version 9.5.1 (9.5.1-g14ed65 @ /home/minshall/.emacs.d/straight/build/org/)
----
cheers, Greg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] bug in 'ox-man?
2022-01-31 14:00 [BUG] bug in 'ox-man? Greg Minshall
@ 2022-02-01 0:25 ` Greg Minshall
2024-04-14 11:20 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Greg Minshall @ 2022-02-01 0:25 UTC (permalink / raw)
To: emacs-orgmode
> #+begin_src bash :results output :exports code :eval never-export
> echo 'lf "\n"'
> #+end_src
it seems that `.man` files are in troff(1) format, which uses backslash
escapes up the wazoo (however that is spelled). it seems that (one way)
to getting a backslash character through troff is representing it as
"\e".
for my *particular* instance, where the backslash is in an org src
block, the below modification to `(org-man-src-block)` may work.
presumably one might have backslash sequences in example blocks, or in
the main text, or ...? i don't know enough to have any idea if there is
some general mechanism that might solve all those.
cheers, Greg
----
From 0d0dadc6b4e7f3358612f056a9eb032c1eb4145f Mon Sep 17 00:00:00 2001
From: Greg Minshall <minshall@umich.edu>
Date: Mon, 31 Jan 2022 16:08:35 -0800
Subject: [PATCH] lisp/ox-man.el: escape backslashes from org src blocks
---
lisp/ox-man.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index e808edcdf..6eb6b5ff8 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -748,7 +748,9 @@ CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
(if (not (plist-get info :man-source-highlight))
(format ".RS\n.nf\n\\fC%s\\fP\n.fi\n.RE\n\n"
- (org-export-format-code-default src-block info))
+ (replace-regexp-in-string
+ "\\\\" "\\\\e"
+ (org-export-format-code-default src-block info)))
(let* ((tmpdir temporary-file-directory)
(in-file (make-temp-name (expand-file-name "srchilite" tmpdir)))
(out-file (make-temp-name (expand-file-name "reshilite" tmpdir)))
--
2.34.1
----
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [BUG] bug in 'ox-man?
2022-02-01 0:25 ` Greg Minshall
@ 2024-04-14 11:20 ` Ihor Radchenko
2024-04-26 9:45 ` Ihor Radchenko
2024-12-18 17:37 ` G. Branden Robinson
0 siblings, 2 replies; 5+ messages in thread
From: Ihor Radchenko @ 2024-04-14 11:20 UTC (permalink / raw)
To: Greg Minshall; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 753 bytes --]
Greg Minshall <minshall@umich.edu> writes:
>> #+begin_src bash :results output :exports code :eval never-export
>> echo 'lf "\n"'
>> #+end_src
>
> it seems that `.man` files are in troff(1) format, which uses backslash
> escapes up the wazoo (however that is spelled). it seems that (one way)
> to getting a backslash character through troff is representing it as
> "\e".
>
> for my *particular* instance, where the backslash is in an org src
> block, the below modification to `(org-man-src-block)` may work.
>
> presumably one might have backslash sequences in example blocks, or in
> the main text, or ...? i don't know enough to have any idea if there is
> some general mechanism that might solve all those.
See the attached tentative patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-man-Escape-backslash-characters-in-verbatim-examp.patch --]
[-- Type: text/x-patch, Size: 3791 bytes --]
From ef3fa244d1a32c2cce3616a6dffc9c3dcafd4e34 Mon Sep 17 00:00:00 2001
Message-ID: <ef3fa244d1a32c2cce3616a6dffc9c3dcafd4e34.1713093571.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sun, 14 Apr 2024 14:05:59 +0300
Subject: [PATCH] ox-man: Escape backslash characters in verbatim examples
* lisp/ox-man.el (org-man--protect-example): New helper function
protecting special escape characters inside literal examples.
(org-man-example-block):
(org-man-inline-src-block):
(org-man-src-block):
(org-man-table): Protect contents that is intended to be rendered
verbatim.
Reported-by: Greg Minshall <minshall@umich.edu>
Link: https://orgmode.org/list/2924644.1643637646@apollo2.minshall.org
---
lisp/ox-man.el | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 958740da8..cdd4fea7d 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -293,6 +293,13 @@ (defun org-man--protect-text (text)
"Protect minus and backslash characters in string TEXT."
(replace-regexp-in-string "-" "\\-" text nil t))
+(defun org-man--protect-example (text)
+ "Escape necessary characters for verbatim TEXT."
+ ;; See man groff_man_style; \e must be used to render backslash.
+ ;; Note that groff's .eo (disable backslash) and .ec (re-enable
+ ;; backslash) cannot be used as per the same man page.
+ (replace-regexp-in-string "\\\\" "\\e" text nil t))
+
\f
;;; Template
@@ -400,7 +407,7 @@ (defun org-man-example-block (example-block _contents info)
(org-man--wrap-label
example-block
(format ".RS\n.nf\n%s\n.fi\n.RE"
- (org-export-format-code-default example-block info))))
+ (org-man--protect-example (org-export-format-code-default example-block info)))))
;;; Export Block
@@ -529,11 +536,11 @@ (defun org-man-inline-src-block (inline-src-block _contents info)
(delete-file out-file)
code-block)
(format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE\n"
- code))))
+ (org-man--protect-example code)))))
;; Do not use a special package: transcode it verbatim.
(t
- (concat ".RS\n.nf\n" "\\fC" "\n" code "\n"
+ (concat ".RS\n.nf\n" "\\fC" "\n" (org-man--protect-example code) "\n"
"\\fP\n.fi\n.RE\n")))))
@@ -749,7 +756,7 @@ (defun org-man-src-block (src-block _contents info)
contextual information."
(if (not (plist-get info :man-source-highlight))
(format ".RS\n.nf\n\\fC%s\\fP\n.fi\n.RE\n\n"
- (org-export-format-code-default src-block info))
+ (org-man--protect-example (org-export-format-code-default src-block info)))
(let* ((tmpdir temporary-file-directory)
(in-file (make-temp-name (expand-file-name "srchilite" tmpdir)))
(out-file (make-temp-name (expand-file-name "reshilite" tmpdir)))
@@ -772,7 +779,7 @@ (defun org-man-src-block (src-block _contents info)
(delete-file in-file)
(delete-file out-file)
code-block)
- (format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE" code)))))
+ (format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE" (org-man--protect-example code))))))
;;; Statistics Cookie
@@ -836,9 +843,10 @@ (defun org-man-table (table contents info)
(format ".nf\n\\fC%s\\fP\n.fi"
;; Re-create table, without affiliated keywords.
- (org-trim
- (org-element-interpret-data
- `(table nil ,@(org-element-contents table))))))
+ (org-man--protect-example
+ (org-trim
+ (org-element-interpret-data
+ `(table nil ,@(org-element-contents table)))))))
;; Case 2: Standard table.
(t (org-man-table--org-table table contents info))))
--
2.44.0
[-- Attachment #3: Type: text/plain, Size: 224 bytes --]
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [BUG] bug in 'ox-man?
2024-04-14 11:20 ` Ihor Radchenko
@ 2024-04-26 9:45 ` Ihor Radchenko
2024-12-18 17:37 ` G. Branden Robinson
1 sibling, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2024-04-26 9:45 UTC (permalink / raw)
To: Greg Minshall; +Cc: emacs-orgmode
Ihor Radchenko <yantar92@posteo.net> writes:
>> presumably one might have backslash sequences in example blocks, or in
>> the main text, or ...? i don't know enough to have any idea if there is
>> some general mechanism that might solve all those.
>
> See the attached tentative patch.
Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=68d592bae
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] bug in 'ox-man?
2024-04-14 11:20 ` Ihor Radchenko
2024-04-26 9:45 ` Ihor Radchenko
@ 2024-12-18 17:37 ` G. Branden Robinson
1 sibling, 0 replies; 5+ messages in thread
From: G. Branden Robinson @ 2024-12-18 17:37 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2563 bytes --]
[please CC me in replies; I am not subscribed to emacs-orgmode]
At 2024-04-14T11:20:28+0000, Ihor Radchenko wrote:
>From ef3fa244d1a32c2cce3616a6dffc9c3dcafd4e34 Mon Sep 17 00:00:00 2001
Message-ID: <ef3fa244d1a32c2cce3616a6dffc9c3dcafd4e34.1713093571.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sun, 14 Apr 2024 14:05:59 +0300
Subject: [PATCH] ox-man: Escape backslash characters in verbatim examples
* lisp/ox-man.el (org-man--protect-example): New helper function
protecting special escape characters inside literal examples.
(org-man-example-block):
(org-man-inline-src-block):
(org-man-src-block):
(org-man-table): Protect contents that is intended to be rendered
verbatim.
Reported-by: Greg Minshall <minshall@umich.edu>
Link: https://orgmode.org/list/2924644.1643637646@apollo2.minshall.org
---
lisp/ox-man.el | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
[snip]
;; Do not use a special package: transcode it verbatim.
(t
- (concat ".RS\n.nf\n" "\\fC" "\n" code "\n"
+ (concat ".RS\n.nf\n" "\\fC" "\n" (org-man--protect-example code) "\n"
"\\fP\n.fi\n.RE\n")))))
I suggest something like:
- (concat ".RS\n.nf\n" "\\fC" "\n" code "\n"
- "\\fP\n.fi\n.RE\n")))))
+ (concat ".RS\n.nf\n" ".EX\n" ".P\n" (org-man--protect-example code) ".P\n"
+ ".EE\n.fi\n.RE\n")))))
I replaced inlined `\fC` and `\fP` escape sequences with `EX` and `EE`
macro calls, respectively.
I also think I perceive the use of empty lines as paragraph separators.
These look bad when typesetting (as opposed to terminal rendering). So
I changed them to be `P` paragraphing macro calls instead.
Also, the `nf` request is redundant with the `EX` macro call and `fi`
with `EE`; I left them in because they are harmless and positively
useful if you're producing a man page for consumption by a non-groff
troff that doesn't support the `EX` and `EE` macros. (mandoc(1)
correctly renders `EX` and `EE`.)
groff_man(7):
.EX and .EE are extensions introduced in Ninth Edition Unix.
Documenter’s Workbench, Heirloom Doctools, and Plan 9
troffs, and mandoc (since 1.12.2) also support them.
Solaris troff does not. See subsection “Use of extensions”
below.
Unless support for Solaris 10 troff is important to you (Solaris 11 uses
groff), `nf` and `fi` are unnecessary and you can take them out too.
Regards,
Branden
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-18 19:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-31 14:00 [BUG] bug in 'ox-man? Greg Minshall
2022-02-01 0:25 ` Greg Minshall
2024-04-14 11:20 ` Ihor Radchenko
2024-04-26 9:45 ` Ihor Radchenko
2024-12-18 17:37 ` G. Branden Robinson
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).