Come definire i tipi di paragrafo personalizzati in modalità organizzazione con la fontificazione personalizzata?

Aug 17 2020

Come posso definire blocchi di paragrafo personalizzati in modalità organizzazione con una fontificazione personalizzata, ad esempio qualcosa di simile

#+BEGIN_MYPAR
Some text 
#+END_MYPAR

Quindi voglio, ad esempio, che questo blocco sia visualizzato con il colore del carattere arancione, un punto più grande del resto del testo, in grassetto e rientrato di una scheda.

Come posso fare questo?

Modifica :

La domanda riguarda come le cose vengono visualizzate nel buffer di emacs, non nelle esportazioni (anche se questa potrebbe essere stata una domanda successiva).

Risposte

2 Tobias Aug 27 2020 at 21:29

Raggiungi il tuo obiettivo in modo abbastanza semplice se usi blocchi sorgente invece di blocchi speciali. Definisci la tua modalità principale, ad esempio mypar-modecon l'aiuto di define-generic-modeo define-derived-modee imposta la fontificazione per quella modalità principale come desideri.

Assicuratevi che org-src-fontify-nativelye org-src-preserve-indentationsiano entrambi impostati in modo tale che i myparblocchi sorgente nel buffer Org assomiglino il più possibile ai buffer sorgente fontefied.

Se hai htmlizeinstallato, ottieni la maggior parte della formattazione desiderata nell'esportazione HTML gratuitamente.

Un esempio di codice che ho testato con Emacs 27.1 e 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)))

(add-hook 'org-mode-hook #'org+-hack-org-fontification)
(setq org-src-fontify-natively t
      org-src-preserve-indentation t)

Finalmente un'immagine di come myparappare un blocco sorgente in Org:

1 Tobias Aug 23 2020 at 23:09

Prima nota, la tua domanda è un po 'vaga. Dove vuoi avere questa formattazione speciale del paragrafo - nell'esportazione HTML o nell'esportazione LaTeX? O anche nella rappresentazione dell'org-buffer in Emacs?

Ti do qui una risposta per l'esportazione in HTML e LaTeX.

L'idea principale per l'esportazione HTML è che MYPARdetermina la classe di stile del testo nel blocco speciale .

Puoi definire il tuo stile all'interno delle #+HTML_HEADmeta-linee.

L'idea principale per l'esportazione LaTeX è che MYPARdetermina l'ambiente LaTeX in cui viene inserito il testo del blocco speciale . Puoi definire quell'ambiente personalizzato all'interno di #+LATEX_HEADERmeta-righe.

Un esempio:

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>
#+LATEX_HEADER: \usepackage{xcolor}
#+LATEX_HEADER: \newdimen\myparindent\myparindent8em
#+LATEX_HEADER: \newdimen\myparwidth\myparwidth\textwidth\advance\myparwidth-\myparindent
#+LATEX_HEADER: \newenvironment{MYPAR}{\par\noindent\hfill\begin{minipage}[t]{\myparwidth}\bf\color{orange}\fontsize{1em}{1.2em}\selectfont}{\par\xdef\tpd{\the\prevdepth}\end{minipage}\par\prevdepth\tpd}
See https://tex.stackexchange.com/questions/35933/indenting-a-whole-paragraph for using ~minipage~ for indenting a whole paragraph.