วิธีกำหนดประเภทย่อหน้าที่กำหนดเองในโหมดองค์กรด้วยการกำหนดแบบอักษรที่กำหนดเอง
ฉันจะกำหนดบล็อคย่อหน้าที่กำหนดเองในโหมดองค์กรด้วยฟอนต์ที่กำหนดเองได้อย่างไรเช่น
#+BEGIN_MYPAR
Some text
#+END_MYPAR
ตัวอย่างเช่นฉันต้องการให้บล็อกนี้แสดงเป็นสีตัวอักษรสีส้มหนึ่งจุดใหญ่กว่าส่วนที่เหลือของข้อความหน้าเป็นตัวหนาและเยื้องทีละแท็บ
ฉันจะทำเช่นนี้ได้อย่างไร?
แก้ไข :
คำถามคือเกี่ยวกับวิธีแสดงสิ่งต่างๆในบัฟเฟอร์ emacs ไม่ใช่ในการส่งออก (แม้ว่าอาจเป็นคำถามติดตามผล)
คำตอบ
คุณบรรลุเป้าหมายได้ค่อนข้างง่ายหากคุณใช้บล็อคซอร์สแทนบล็อกพิเศษ กำหนดโหมดหลักของคุณเองพูดmypar-mode
ด้วยความช่วยเหลือdefine-generic-mode
หรือdefine-derived-mode
และตั้งค่าแบบอักษรสำหรับโหมดหลักนั้น ๆ ตามที่คุณต้องการ
ตรวจสอบให้แน่ใจว่าorg-src-fontify-natively
และorg-src-preserve-indentation
เป็นชุดทั้ง t ดังกล่าวที่mypar
บล็อกแหล่งที่มาในองค์กร buffer ดูมากที่สุดเท่าที่เป็นไปได้เช่นบัฟเฟอร์แหล่ง fontified
หากคุณhtmlizeติดตั้งแล้วคุณจะได้รูปแบบที่ต้องการส่วนใหญ่ในการส่งออก HTML ฟรี
ตัวอย่างโค้ดที่ฉันได้ทดสอบกับ Emacs 27.1 และ 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)
ในที่สุดภาพmypar
ลักษณะของบล็อกซอร์สในองค์กร:

ก่อนอื่นโปรดทราบว่าคำถามของคุณค่อนข้างคลุมเครือ คุณต้องการจัดรูปแบบย่อหน้าแบบพิเศษนี้ที่ไหนใน HTML-export หรือ LaTeX-export หรือแม้แต่ในการเป็นตัวแทนของ Org-buffer ใน Emacs?
ฉันให้คำตอบสำหรับ HTML- และ LaTeX-export
แนวคิดหลักเพื่อใช้ HTML ส่งออกคือการที่MYPAR
กำหนดระดับลักษณะของข้อความในบล็อกพิเศษ
คุณสามารถกำหนดสไตล์ของคุณเองได้ภายใน#+HTML_HEAD
เมตาไลน์
แนวคิดหลักสำหรับ LaTeX-export คือMYPAR
กำหนดสภาพแวดล้อม LaTeX ที่ใส่ข้อความของบล็อกพิเศษคุณสามารถกำหนดสภาพแวดล้อมแบบกำหนดเองภายใน#+LATEX_HEADER
เมตา - ไลน์
ตัวอย่าง:
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.