From: BH <bewihelm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: markdown - pdf two way sync
Date: Sat, 14 May 2016 08:50:25 -0700 (PDT) [thread overview]
Message-ID: <d6c717a4-11c4-47f7-88b7-37ff0f9b394f@googlegroups.com> (raw)
In-Reply-To: <20160503183852.GA21146-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 2975 bytes --]
On Tuesday, May 3, 2016 at 2:39:05 PM UTC-4, John MacFarlane wrote:
>
> Pandoc doesn't store any source-mapping information in
> the AST.
>
This is, of course, right, but two-way sync (in both directions) is
possible nonetheless (albeit in a way that's quite fragile). Here's the
rough idea (both requiring that pdfsync be used when compiling the .pdf
file):
1. For backward search (from .pdf to .md): have the .pdf viewer send the
source (.tex) file and line number to a script that (a) reads in the
relevant line from the .tex file, (b) extracts a reasonable-sized chunk of
text, (c) searches for that text in the corresponding markdown file, and
finally (d) sends the line number of that text to the text editor.
2. For forward search (from .md to .pdf) do the opposite: have the text
editor send the source (.md) file and line number to a script that (a)
reads in the relevant line from the .md file, (b) extracts a
reasonable-sized chunk of text, (c) searches for that text in the
corresponding .tex file, and finally (d) sends the line number of that text
to the .pdf viewer.
Clearly, a problem lies in step (b) in both cases: how do you locate the
relevant text to use in searching the corresponding file for? What I've
done differs between (1) and (2).
In (2), I find it easiest to take the whole line of markdown, strip off any
initial markdown codes (such as those for enumerated lists), run it through
pandoc (using exactly the same options I use to generate the .pdf in the
first place) to convert to LaTeX, and then search for this in the .tex file.
In (1), I find I need to use a different strategy, since .tex -> .md
conversion in pandoc often fails to produce a match in the .md file. (This
is partly because of the way I have extended markdown using some filters.)
So here I try to locate a stretch of text in the .tex file that does not
contain any LaTeX commands as follows: I try searching for the first
occurrence of '\' in the relevant line, and if this occurs deep enough into
the text, I grab text from the beginning of the line to that point. If not,
I look for a stretch of text after that '\' that occurs between '{' and
'}'. Usually this is good enough to find a unique match in the markdown
file.
As I said, this is fragile: it won't work in every case, but for me it
works about 90-95% of the time, which is good enough for my purposes.
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d6c717a4-11c4-47f7-88b7-37ff0f9b394f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 3723 bytes --]
next prev parent reply other threads:[~2016-05-14 15:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-03 9:42 Andrey Ustyuzhanin
[not found] ` <aeb78b6e-ed06-4d86-ac4b-0a6d7385fbf7-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-05-03 18:38 ` John MACFARLANE
[not found] ` <20160503183852.GA21146-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
2016-05-14 15:50 ` BH [this message]
[not found] ` <d6c717a4-11c4-47f7-88b7-37ff0f9b394f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-05-23 8:50 ` J
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=d6c717a4-11c4-47f7-88b7-37ff0f9b394f@googlegroups.com \
--to=bewihelm-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).