From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IMo4DyRAemLNDgEAbAwnHQ (envelope-from ) for ; Tue, 10 May 2022 12:36:20 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id oHdrDiRAemKrwQAAG6o9tA (envelope-from ) for ; Tue, 10 May 2022 12:36:20 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B0303CA75 for ; Tue, 10 May 2022 12:36:19 +0200 (CEST) Received: from localhost ([::1]:57888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noNE2-0004Dr-Hz for larch@yhetil.org; Tue, 10 May 2022 06:36:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noNAm-0002Bn-1o for emacs-orgmode@gnu.org; Tue, 10 May 2022 06:32:56 -0400 Received: from mout01.posteo.de ([185.67.36.65]:54303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noNAh-0003sr-SE for emacs-orgmode@gnu.org; Tue, 10 May 2022 06:32:54 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id C8BD0240028 for ; Tue, 10 May 2022 12:32:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1652178766; bh=dxHU+7n0Boo8Jvs2wIdfzgdU9cfjbLmu2BThXnkZ7AE=; h=From:To:Subject:Date:From; b=hAd71mmAZZmbL7c4gSzIuKvHTWqykmO0l/doUpRglTxZk5Xwx5Nu+2i0s9Ii9X/QL r/czp8D6y+YxJj1vLaEoaGQTOurjgXzw8o6BmWoWaCqV41QCEmoLCiYd9j1Ovl7DMl w6phyeyT3TZ7diBiALB3WhvVTs1iwG7qffCDKJ2G6GJeJ3Tw4u9NpWkEh8+5FDaUhI Ae+dPKySxRv8wWdJvc6Q4rSXseJmSX5khIAz+Va8hAb+rvkkikvllh6EzGOQJvYa5I hZMGb4Iu1oJ/WdXBIvPmd5cwlqSNZmsYbSE6Skc9Yrd4IbofQawOUmkVysHz9Jo5Jl GyROZCF737BEw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4KyDrZ0hxrz9rxR for ; Tue, 10 May 2022 12:32:45 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: A function that converts a LaTeX document to an Elisp expression (for org-latex-classes) Date: Tue, 10 May 2022 10:32:51 +0000 Message-ID: <87czgly8x8.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1652178979; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=lAqksQiJ1IAKcGxp4DvGNPXifCciBaw+Z7F3+Q78QBg=; b=qI+EMLRIXz4WPhhbx/MkO79ZJ+acLo+zub/mHFv66dzmrGe/oc9ip+5z72CXx1c0zUQ26S yKJD8V3oAEnwL9slMACucCaTYHXuLgNsNGcZV+78UO9+C4kfGQWThllXXlM8DMXm8loSfo vKk/SF3xhotp9C7HwMe9dUsyGL6QI3yvoKBef/JJ8eUnmHxUu5Wuk/9o44y1kGV5dZhNMP 96kEwd08/vlzwVf+0Ws7PwvaS3W8koAPvypXyzrNovOF0+amO2RKpDW6mcKH2oNJO5k2MC l0g01ZdyoDqZJTDEBpMy4Nrz4TxKuLgiSo/5zarq+d0EnFAtfozt4Zeqf47sgQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652178979; a=rsa-sha256; cv=none; b=o9eo839x6WERlZp741AmKXyddml5Ija2sF3pDI7R49bsDK+PyuYib4w+cbQRYA9U3fvvaH XQY+/EjKCv96sWXMF0EvK4gx85gm+Kdzj7FHFCtXxVsquDkHMC7Ad+OBFxoa+b92PbNgfc 17ui91an1Ur0AJM6JgYx8vgO265lQX0ad/PYB5OEfeDXQkJfdAaHAQZ9aMVkbCLLUTE8e0 Nr87yRsp/FjmPsv3Rrq3YobZUwOZdUsdp04WfBD/MumNGPKXhiTWexEJzidVFdI37WzxZ+ eOqtYFZHEKoqBr1QjhO1kqS4o3DrO0NgfGIAaf8amHswx0wnl9D1vafT5PTJ4g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=hAd71mmA; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -9.50 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=hAd71mmA; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: B0303CA75 X-Spam-Score: -9.50 X-Migadu-Scanner: scn0.migadu.com X-TUID: DolVEc2HKmmN Hi all, In case anyone finds it useful, I'm sharing this function here that I recently wrote, to convert a LaTeX buffer to an Elisp expression, suitable for adding to `org-latex-classes'. It's a bit rudimentary, but I think it does the trick. It can be useful for long preambles with a lot of (La)TeX code. Although if you are dealing with bizarrely large preambles that are used often, I would recommend writing your own .sty file (https://tex.stackexchange.com/questions/8750/make-your-own-sty-files). The funny thing is that doing it from Org is much easier than from the official LaTeX utility for creating packages through literary programming, docstrip. As for my function, the LaTeX document to be converted must have this skeleton: - Preamble - `\begin{document}' - An ordered list of section names (one name per line). For example: chapter section subsection susbsubsection etc - `\end{document}' Best regards, Juan Manuel #+begin_src emacs-lisp (defun create-new-org-latex-class-from-latex-buffer () "Convert the current LaTeX buffer to an appropriate Elisp expression to add to `org-latex-classes'. The LaTeX document must have the following structure: - Preamble - `\begin{document}' - A list of section names (one name per line). For example: section subsection susbsubsection etc - `\end{document}'" (interactive) (if (not (equal (format "%s" major-mode) "latex-mode")) (error "Not in a LaTeX buffer") (let* ((class-name (read-from-minibuffer "Class name: ")) (preamble-beg (with-current-buffer (buffer-name) (save-excursion (goto-char (point-min)) (point)))) (preamble-end (with-current-buffer (buffer-name) (save-excursion (goto-char (point-min)) (re-search-forward "\\\\begin{document}" nil t) (beginning-of-line) (point)))) (packages "[NO-DEFAULT-PACKAGES] [PACKAGES] [EXTRA]") (preamble (concat (buffer-substring-no-properties preamble-beg preamble-end) packages)) (preamble-list (list preamble)) (sections-list) (sections-list-populate (with-current-buffer (buffer-name) (save-excursion (goto-char (point-min)) (let ((beg-sec (save-excursion (re-search-forward "\\\\begin{document}" nil t) (point))) (end-sec (save-excursion (re-search-forward "\\\\end{document}" nil t) (beginning-of-line) (point)))) (save-restriction (narrow-to-region beg-sec end-sec) (while (re-search-forward "\\(^.+\\)" nil t) (push (substring-no-properties (match-string 1)) sections-list))) (reverse sections-list))))) (section-list-final (mapcar (lambda (x) (let ((car (format "\\%s{%%s}" x)) (cdr (format "\\%s*{%%s}" x))) (cons car cdr))) sections-list-populate)) (list-final (append (list class-name) preamble-list section-list-final)) (format-list (format "%S" list-final))) (when (get-buffer "*class*") (kill-buffer "*class*")) (get-buffer-create "*class*") (with-current-buffer "*class*" (insert format-list)) (temp-buffer-window-show "*class*")))) #+end_src