# How to define custom paragraph types in org mode with custom fontification?

How can I define custom paragraph blocks in org mode with a custom fontification, for example something like

#+BEGIN_MYPAR
Some text
#+END_MYPAR


Then I want for example that this block is displayed in orange font color, one point larger than the rest of the text, bold face and indented by one tab.

How can I do this?

Edit:

The question is about how things are displayed in the emacs buffer, not in exports (though this may have been a follow up question).

You reach your goal quite simple if you use source blocks instead of special blocks. Define your own major mode, say mypar-mode with the help of define-generic-mode or define-derived-mode and setup the fontification for that major mode like you want it.

Make sure that org-src-fontify-natively and org-src-preserve-indentation are both set to t such that the mypar source blocks in the Org buffer look as much as possible like the fontified source buffers.

If you have htmlize installed you get most of the wanted formatting in the HTML export for free.

A code example that I have tested with Emacs 27.1 and Org 9.3.7:

(require 'org)
(require 'cl-lib)
(define-generic-mode mypar-mode
nil ;; comment-list
nil ;; keyword-list
;; font-lock-list:
'(("^.*\$"
;; match-highlight:
(0 ;; subexpression
;; facename:
(face (:inherit default :foreground "orange" :height 1.5 :weight bold) ;; we use an anonymous face
;; indent:
line-prefix "\t"
wrap-prefix "\t")
)))
nil ;; auto-mode-list
'((lambda ()
"Make line-prefix' and wrap-prefix' work in the source fontification buffer."
(setq-local font-lock-extra-managed-props '(line-prefix wrap-prefix))
));; function-list
"Formatting MYPAR blocks.")

(defun org+-hack-org-fontification ()
"Make wrap-prefix' and line-prefix' text properties work in Org buffers."
(setq-local font-lock-extra-managed-props (cl-union
'(line-prefix wrap-prefix)
font-lock-extra-managed-props)))

(setq org-src-fontify-natively t
org-src-preserve-indentation t)


At last an image how a mypar source block looks like in Org:

• Is there an option such that latex fragment previews work also in your mypar environment? Sep 17 '20 at 6:37

First note, that your question is a bit vague. Where do you want to have this special formatting of the paragraph -- in HTML-export or LaTeX-export? Or even in the representation of the Org-buffer in Emacs?

I give you here an answer for HTML- and LaTeX-export.

The main idea for HTML-export is that MYPAR determines the style class of the text in the special block.

You can define your own style within #+HTML_HEAD meta-lines.

The main idea for LaTeX-export is that MYPAR determines the LaTeX environment where the text of the special block is put in. You can define that custom environment within #+LATEX_HEADER meta-lines.

An example:

Some text before my paragraph. Let this paragraph have some more text. It should have at least two lines.
#+BEGIN_MYPAR
Some text in my paragraph. Let this paragraph have some more text. It should have at least two lines. Even a third line would be nice to have. So we continue this text for some time.
#+END_MYPAR
Some text after my paragraph. Let this paragraph have some more text. It should have at least two lines.

* Style :noexport:
This section is just for definition of HTML and LaTeX formatting.
#+HTML_HEAD: <style>.MYPAR { color:orange; text-indent:8em; font-weight:bold; foint-size:110% }</style>
`