From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/28727 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: jcr Newsgroups: gmane.text.pandoc Subject: Re: How to get \section[Short title]{Long title} in LaTeX output Date: Wed, 30 Jun 2021 08:04:49 -0700 (PDT) Message-ID: <20fccf69-3cde-450a-ad6f-f7c2ae9b2531n@googlegroups.com> References: <4p2Sx0e_CqUgNm9ZcXR064fya9gybYYDVBTVMMIL9p1m2ynHgBzs30shkkVJnu0l2RqSKghQo5oi10jSV33BS6IBsvIhBhtyoExu-d3p3Kc=@protonmail.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_1052_238173853.1625065489603" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7615"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDQLFNXWVILBBEUQ6KDAMGQEG4XQUCA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jun 30 17:04:53 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f64.google.com ([209.85.210.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lybll-0001fF-Ab for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 30 Jun 2021 17:04:53 +0200 Original-Received: by mail-ot1-f64.google.com with SMTP id m26-20020a0568301e7ab0290465faca518fsf1824074otr.18 for ; Wed, 30 Jun 2021 08:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=eRdDDZUoh0ofrBVmvVm8H8F/752QpCWI/Q3nfT0NUJM=; b=l6Y6fbwLjco/UW7wc85Hm4bciadrr6ylWqOdpSxcy8trZM9tV1qtzlY9Wni7Fpz6zh uP2XY1nWYlwT8ZVLTmOKy42YtpHZwiBHfo6coGocXDudeEgrLgnoEBQHKhBQHlEB0aPH 6XjBlHlNoBz2++3Fqi5KE5JEwdD65zQvqoiDXGQgfjiYDE7VGsnHC8Gp83ngUeRuPFDU uAaZT48s9VzWOBWHL6MpgIu0ePtW1/H3jW7kDgrTciFrSnZNudV0PIAgGB7eNJLr3zyz 5VUaikk8ZLkIBfFoMy+5V6xDOX8tXCPwA9A4ws6lX4XoOTTRdMIZ8/EjrkPAbkDnBSpq UH4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=eRdDDZUoh0ofrBVmvVm8H8F/752QpCWI/Q3nfT0NUJM=; b=eIZQETAkdBg+BCb0hmeMCn4Jn/AfiFG5SQ1nZzATNMQnjEoCSJ6gvqPuLMyj5zjHsA pIAviLy/Yz9SPfVRlMLZ671oNXJs9yuhtZzQQcKM02hX0shy8FqHI76qgwF9SCfyxLr/ hxo2hjie747/d2n7dLm3xpIOXNAFYgruC+cy7B39EA6txM2b3zW1WUfNmEOk8Y+Pa93o Q9syv7iT5s+YKiWb6mgMNISSiT6rmnFSD6eH9kvmPP6d/cP3PH55kirRh/2i6DS2m5mL mX5gZOI+uOqJT5mdXvN/O1XNIgxI10IxHrHJMrDURSO+BH/dC+1lPI+y0tPEgebHGbNz 98EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=eRdDDZUoh0ofrBVmvVm8H8F/752QpCWI/Q3nfT0NUJM=; b=bv+OsNLMx5jOoJxVbmP37L98ta2Hx6/SkA0Jccd9Z00lNrTkyx6ZfB4cayVPPvbVjV W2J60OTy0FSB5YQ0WNWJODVTifXLmhfCSMNhJ3NNQRpc3oBit7SlatXu7MTwul9sZCaF UES21VvSmBhkA5y5GLZ+2xRCwBxGo7T5VTHFSdTsT2EV9FCagLIC+8AFJS7TPwJZas5F cMy+8++rmywRZjEyYnp2rBKUFV3cZ6d+IwBanzMuxJezsGXowBSIVjnbC15S4+2v/499 iaLdvRms6XPOxmdHspsBccPL7iSmazBkYjvEXI4mhJzs6j+cOb1ov1yQHcVg7BkH/FkO q0OQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532T4f4OAxO+6pqoVG4zkPNPP7Pn5Vlf/PJsnVW/oTIaB2aLaety MGyhrOS9bavyPcVN9HN8qY8= X-Google-Smtp-Source: ABdhPJwbXS5+LXSlvnXEFYQwqPWW4vVvuG974IE4HsYh6Vm1o8nA3iCCBm24u0eUafb5cc4TU1Q9PA== X-Received: by 2002:aca:dac5:: with SMTP id r188mr3424009oig.100.1625065492390; Wed, 30 Jun 2021 08:04:52 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a4a:4990:: with SMTP id z138ls219731ooa.11.gmail; Wed, 30 Jun 2021 08:04:50 -0700 (PDT) X-Received: by 2002:a4a:37d6:: with SMTP id r205mr8755886oor.86.1625065490230; Wed, 30 Jun 2021 08:04:50 -0700 (PDT) In-Reply-To: X-Original-Sender: ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:28727 Archived-At: ------=_Part_1052_238173853.1625065489603 Content-Type: multipart/alternative; boundary="----=_Part_1053_473610632.1625065489603" ------=_Part_1053_473610632.1625065489603 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Others can correct me if I'm wrong, but I don't think the filter has enough= =20 information to tell in all cases what a level 1 header corresponds to in=20 LaTeX. If documentclass is specified in the metadata, you could deduce=20 whether chapter or section will be selected by default. However,=20 --top-level-headings (or the documentclass variable?) could override the=20 metadata. On Wednesday, June 30, 2021 at 2:30:07 PM UTC+2 Nick Bart wrote: > @jcr - Brilliant, works like a charm. I had to make some trivial changes;= =20 > the version I=E2=80=99m using right now with the LaTeX article or scrartc= l classes=20 > is shown below.=20 > > One thing that would be nice to have, though, would be the ability to=20 > switch automatically between a 'commands' list for book-like LaTeX classe= s=20 > (starting with 'chapter'), and article-like classes (starting with=20 > 'section'). I'll be trying to figure that out, but useful hints would be= =20 > welcome. > > -- Print a formatted warning to stderr > function warnf (...) > io.stderr:write(string.format(...)) > end > function Header (el) > -- Replace heading with raw LaTeX if pageheading is used to specify a > -- shorter form of the title to use in page headers. > if el.attributes.pageheading then > -- local commands =3D {'chapter', 'section', 'subsection'} > local commands =3D {'section', 'subsection'} > if el.level > #commands then > warnf('pageheading attribute not supported for level %d headings',= =20 > el.level) > return el > end > -- Produce LaTeX like pandoc does, but with two additional arguments > -- to specify a short for of the page heading to memoir. > local title =3D pandoc.utils.stringify(el) > -- local latexStr =3D string.format('\\%s[%s][%s]{%s}',=20 > commands[el.level], title, el.attributes.pageheading, title) > local latexStr =3D string.format('\\%s[%s]{%s}', commands[el.level],= =20 > el.attributes.pageheading, title) > local label =3D string.format('\\label{%s}', el.identifier) > -- wrap in hypertarget > latexStr =3D string.format('\\hypertarget{%s}{%%\n%s%s}', el.identifi= er,=20 > latexStr, label) > return pandoc.RawBlock('latex', latexStr) > end > end > > --=20 You received this message because you are subscribed to the Google Groups "= pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/= pandoc-discuss/20fccf69-3cde-450a-ad6f-f7c2ae9b2531n%40googlegroups.com. ------=_Part_1053_473610632.1625065489603 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Others can correct me if I'm wrong, but I don't think the filter has enough= information to tell in all cases what a level 1 header corresponds to in L= aTeX. If documentclass is specified in the metadata, you could deduce wheth= er chapter or section will be selected by default. However, --top-level-hea= dings (or the documentclass variable?) could override the metadata.

=
On Wednes= day, June 30, 2021 at 2:30:07 PM UTC+2 Nick Bart wrote:
@jcr - Brilliant, works lik= e a charm. I had to make some trivial changes; the version I=E2=80=99m usin= g right now with the LaTeX article or scrartcl classes is shown below.
=

One thing that would be nice to have, though, wou= ld be the ability to switch automatically between a 'commands' list= for book-like LaTeX classes (starting with 'chapter'), and article= -like classes (starting with 'section'). I'll be trying to figu= re that out, but useful hints would be welcome.

-- Print a formatted warning to stderr
function warnf (...)=
=C2=A0 io.stderr:write(string.format(...))
end=
function Header (el)
=C2=A0 -- Replace heading= with raw LaTeX if pageheading is used to specify a
=C2=A0 --= shorter form of the title to use in page headers.
=C2=A0 if = el.attributes.pageheading then
=C2=A0=C2=A0=C2=A0 -- local co= mmands =3D {'chapter', 'section', 'subsection'}
=
=C2=A0=C2=A0=C2=A0 local commands =3D {'section', 's= ubsection'}
=C2=A0=C2=A0=C2=A0 if el.level > #commands= then
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 warnf('pageheading a= ttribute not supported for level %d headings', el.level)
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return el
=C2=A0=C2=A0=C2=A0 e= nd
=C2=A0=C2=A0=C2=A0 -- Produce LaTeX like pandoc does, but = with two additional arguments
=C2=A0=C2=A0=C2=A0 -- to specif= y a short for of the page heading to memoir.
=C2=A0=C2=A0=C2= =A0 local title =3D pandoc.utils.stringify(el)
=C2=A0=C2=A0= =C2=A0 -- local latexStr =3D string.format('\\%s[%s][%s]{%s}', comm= ands[el.level], title, el.attributes.pageheading, title)
=C2= =A0=C2=A0=C2=A0 local latexStr =3D string.format('\\%s[%s]{%s}', co= mmands[el.level], el.attributes.pageheading, title)
=C2=A0=C2= =A0=C2=A0 local label =3D string.format('\\label{%s}', el.identifie= r)
=C2=A0=C2=A0=C2=A0 -- wrap in hypertarget
= =C2=A0=C2=A0=C2=A0 latexStr =3D string.format('\\hypertarget{%s}{%%\n%s= %s}', el.identifier, latexStr, label)
=C2=A0=C2=A0=C2=A0 = return pandoc.RawBlock('latex', latexStr)
=C2=A0 end<= br>
end

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/20fccf69-3cde-450a-ad6f-f7c2ae9b2531n%40googlegroups.= com.
------=_Part_1053_473610632.1625065489603-- ------=_Part_1052_238173853.1625065489603--