mo-seph / obsidian-copy-as-latex

Quick plugin to be able to copy/paste from Obsidian/Markdown into a Latex document
MIT License
35 stars 8 forks source link

\citet and \citep #10

Open SebastianBehrens opened 2 years ago

SebastianBehrens commented 2 years ago

When writing academic papers one usually uses the LaTeX commands \citep and \citet all the time.

For now only \autocite is incorporated from [[@source]] in obsidian-md.

It would be useful if one could switch between \autocite and \citep for [[@source]]. Also, it would be useful if one create use in-text citations such as "Berger and Johnson (2019) have argued..." done with \citet in LaTeX from @source in obsidian-md.

(so no square brackets around the @<whatever> — regex look-ahead and regex-lookbehind to check for "no square brackets sourrounding 'me'?)

mo-seph commented 2 years ago

Yeah, agreed! I haven't figured out a nice way to do this - sitting between Markdown/Obsidian rendering and the markdown parser I can use, and latex is tricky. I don't think @source on it's own would work: I'm currently not getting that as a link, although I could parse it, and it wouldn't show up as a link in Obsidian

One possibility might be to work with the previous enhancement to allow ([[@ref]] p.37) to turn into \autocite[p.37]{ref}. It could maybe be that ([[@ref]]) turns into \citet{ref} - would that make sense? It's a bit much punctuation, but should be manageable.

mo-seph commented 2 years ago

@SebastianBehrens - The new release should help with this - have a look at #11 If you let me know what you think should happen, I'll add it to the set of templates

SebastianBehrens commented 2 years ago

Wow. That was quick. Thank you for that!

Would it be possible to customise the regex-to-latex-citation pairing? (Assuming you use regex to catch the citations) Like a line where one can enter in one field the regex pattern and the latex citation?

With obsidian-md being so personal and individual, it would be great to also keep your own writing and citation styles in obsidian-md. With regexr.com everybody can then create his own mappings from text selection to latex-citation.

Example: citet use case for me: \@\w+(\s\(.*\))* gets "According ==@doe (p.26)==, ..." and "According ==@doe== ... (p. 26)." citep use case for me: \(.*(?=\[)\[\[\@\w+\]\](\,.*)*\) gets "text ==(cf. [[@doe]], p. 26)=="

I am not sure how one can then tell regex where to split for pre, ref and post parts that (I think) every citation command has, but that would also be necessary to then get the final latex citation. But I would assume you have figured that part out already.

What do you think?

Edit: I guess an easy workaround would be to just add templates (such as mine above) manually for those who ask on here. If there is just me, that might work, but, not knowing how many will use the plugin, it might pile up. But of course this is github, there are plenty of helpers that like to help if they can.