Score:2

How to transfer diff between two different file formats?

pe flag

I often find it convenient to edit a document in one file format while storing it in another format. For example, a document can be written down in markdown, converted to a word file and edited there. And I am hoping to extract the edits and applied them back to original markdown file.

So, I would have A.md, converted to A.docx (e.g. using pandoc), edited to B.docx, and somehow apply the change set between A.docx and B.docx to A.md.

My question is:

Is there a reliable/automatic way to transfer the edits in word (text edits) back to the text-based files?

Of course, I can just convert B.docx back to a markdown B.md and overwrite A.md with B.md. But the conversion process often introduces irreversible changes so that the loop A.md => A.docx => A2.md will produce a different A2.md than the original markdown file A.md. Some effects will be added/lost (due to different newlines, fonts, formatting etc.). And I'd like to avoid such loss, and keep the final document as close to the original file A.md as possible.

Would it be possible to use diff/patch to do the following conversions in bash scripts:

  1. A.md => A.docx => A2.md

  2. A.docx => (edits) B.docx

  3. B.docx => B.md

  4. diff B.md A2.md somehow to get a portable patch

  5. apply the patch file on A.md (instead of A2.md)

I have limited experience in using git diff, but not much with directly using diff/patch. And I was wondering if someone can help explain the command sequence needed for such "transfer" of differences.

pLumo avatar
in flag
Why don't you edit `A.md` directly ? There are [markdown editors available](https://askubuntu.com/questions/1189934/is-there-a-markdown-rich-text-editor).
tinlyx avatar
pe flag
@pLumo `Why don't you edit A.md directly ?`. I work with others who might use a different file format/editor.
pLumo avatar
in flag
You should agree with the others for one file format ;-) I guess that is not possible what you want.
tinlyx avatar
pe flag
@pLumo Yeah, in an ideal world.
pLumo avatar
in flag
Or use an online editor where you can work together.
N0rbert avatar
zw flag
Sounds and looks too complicated. As an alternative see https://askubuntu.com/a/1365833/66509 for RMarkdown + bookdown workflow. It works great with Git and plain RMarkdown files.
Score:0
ng flag

The bash syntax for what you ask (steps 4,5) is:

diff B.md A2.md > patch.data 
patch A.md patch.data

I think you may have the files reversed in the diff? And keep in mind patch over-writes A.md so make a copy if you need the original.

In any case, I am skeptical you will be successful with this approach.

To my mind, the Word editor introduces too much non-determinism for any automated conversion to be considered "reliable". Even if you get a script working, you could wind up having to repair it with every update of your Word editor.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.