public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Unable to center text in Markdown
Date: Wed, 12 Oct 2022 12:23:28 +0200	[thread overview]
Message-ID: <CADAJKhC5qHx9gM9Djy10kVcSukADS6sCZsHXnQw-u2Aiwjx+Qg@mail.gmail.com> (raw)
In-Reply-To: <CAPKRM+Uv6Sg_x6sYRvp0R9xhu77=Yn3wk+em5hun5xZ4WoWvOQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 3267 bytes --]

If you delimit the LaTeX commands you can put Markdown between them:

`\begin{center}`{=latex}Markdown *here*`\end{center}`{=latex}

or more realistically with raw blocks:

```{=latex}
\begin{center}
```

Some *Markdown* text goes here!

```{=latex}
\end{center}
```

Or you can use the attached filter (instructions inside!) and just type

:::center
Some *centered* text here
:::

which will allow your source to work for both HTML and LaTeX output.

Den tis 11 okt. 2022 22:15Richard Hu <richardyusen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> Hi gnpan,
>
> Thanks! Your solution works, but I cannot put text formatted with Markdown
> between the \begin{center} ... \end{center} LaTeX tags.
> It seems like Pandoc understands the HTML (e.g. <h1> ... </h1>), but just
> refuses to acknowledge any alignment options specified.
>
>
> On Tue, Oct 11, 2022 at 7:27 PM gnpan <g.panayotou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>> Since you are converting to pdf, you could try some LaTeX, e.g.:
>> \begin{center}{Your text here}\end{center}
>>
>>
>> On Tuesday, 11 October 2022 at 17:39:03 UTC+3 richar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
>>
>>> Hello!
>>>
>>> I'm trying to center some text in my markdown document. I've tried:
>>> ```
>>> <p align="center"> Sample Text </p>
>>> <center> Sample Text </p>
>>> ```
>>> And used `pandoc test.md -o test.pdf` to compile my document. However,
>>> the text shows up as left-aligned and not centered.
>>>
>>> How may I resolve this issue?
>>>
>>> Thank you.
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "pandoc-discuss" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/pandoc-discuss/xP71D6PnL2k/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email 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/2d6fdf96-2731-4970-a9eb-0f0d89e92c37n%40googlegroups.com
>> <https://groups.google.com/d/msgid/pandoc-discuss/2d6fdf96-2731-4970-a9eb-0f0d89e92c37n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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
> email 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/CAPKRM%2BUv6Sg_x6sYRvp0R9xhu77%3DYn3wk%2Bem5hun5xZ4WoWvOQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/pandoc-discuss/CAPKRM%2BUv6Sg_x6sYRvp0R9xhu77%3DYn3wk%2Bem5hun5xZ4WoWvOQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 email 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/CADAJKhC5qHx9gM9Djy10kVcSukADS6sCZsHXnQw-u2Aiwjx%2BQg%40mail.gmail.com.

[-- Attachment #1.2: Type: text/html, Size: 5730 bytes --]

[-- Attachment #2: center-latex.lua --]
[-- Type: application/octet-stream, Size: 2118 bytes --]

--[==============================[
# `center-latex.lua`

A pandoc filter which turns Markdown like this

    :::center
    Some *Markdown* text goes here!
    :::

into LaTeX like this

    \begin{center}

    Some \emph{Markdown} text goes here!

    \end{center}

by saying on the command line

    pandoc -L center-latex.lua my-doc.md -so my-doc.ltx

or

    pandoc -L center-latex.lua my-doc.md -o my-doc.pdf

## Rationale

This is useful e.g. if you want to generate both LaTeX/PDF and HTML from
the same source, or just want to type less and have clean-looking source.

# Installation

Place the file `center-latex.lua` in the `filters` subdirectory/folder
of your Pandoc user directory. To see where the user directory goes inspect
the output of `pandoc --version`. This is typically

    $HOME/.local/share/pandoc/filters 

on Linux and MacOS and

    C:\Users\USERNAME\AppData\Roaming\pandoc\filters

on Windows. You may need to create these directories first.
On Linux/MacOS:

    mkdir -p ~/.local/share/pandoc/filters

and on Windows typically

    md C:\Users\USERNAME\AppData\Roaming\pandoc\filters

--]==============================]

if 'latex' == FORMAT then
  -- Define once, use many times
  local begin_center = pandoc.RawBlock('latex', '\\begin{center}')
  local end_center = pandoc.RawBlock('latex', '\\end{center}')
  
  -- This is a "global"/non-local function
  function Div(div)
    -- Does the div have a class .center?
    if div.classes:includes('center') then
      -- We return just the content of the div
      local rv = div.content
      rv:insert(1, begin_center)  -- prepend
      rv:insert(end_center)       -- append
      return rv
    end
    -- else if no .center class do nothing
    return nil
  end
else
  -- Minimal no-op function so the filter isn't "empty"
  function Pandoc() return nil end
end

--[==============================[
## Copyright and license

This software is Copyright (c) 2022 by Benct Philip Jonsson.

This is free software, licensed under:

  The MIT (X11) License

http://www.opensource.org/licenses/mit-license.php
--]==============================]

      parent reply	other threads:[~2022-10-12 10:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11 14:39 Richard Hu
     [not found] ` <5466ba6b-31e3-4288-a86b-32463bdefe32n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-10-11 14:44   ` Craig Parker
2022-10-11 18:27   ` gnpan
     [not found]     ` <2d6fdf96-2731-4970-a9eb-0f0d89e92c37n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-10-11 20:14       ` Richard Hu
     [not found]         ` <CAPKRM+Uv6Sg_x6sYRvp0R9xhu77=Yn3wk+em5hun5xZ4WoWvOQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-10-12 10:23           ` BPJ [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADAJKhC5qHx9gM9Djy10kVcSukADS6sCZsHXnQw-u2Aiwjx+Qg@mail.gmail.com \
    --to=melroch-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).