I have been experimenting with nbdev on and off for past few days . Having spending most of my time on trying to work on a model on notebooks and then trying to extract relevant module and scripts to provide some common functionality to my team to minimize replication, I see this tool as great fit for daily workflow for our data science team.
I would like to figure out a way to include citation in my exported output . On jupyter side I am able to use cite2c package to view by refences .
Some of the attempts after doing preliminary google search suggested jekyll-scholar plugin for cite2proc-js which I believe is used internally in cite2c but my knowledge is very limited on jekyll, js or jupyter plugin side.
Please suggest if there is a recommended or alternate workflow to include citation ( inline and as references at the end) with nbdev
Thank you for your response and wonderful libraries you have been introducing through fastai. I am learning more about coding and data science just by copy pasting your code line by line than anything else available presently.
I have now explored a bit more on your suggestion and it still doesnât exactly provide what I need . Here are some of my findings
Markdown operations related to kramdown macros(if we can call them that) are constrained with in a jupyter markdown cell. When I try to do footnotes with in the same cells output is rendered . However , it doesnât work when they are separated. I have few guesses on why this might be the case
I have also found a kramdown-cite package . But I doubt it will work across multiple cells
Although I am mostly a python person, I have recently finished a significant technical report (~100-120 pages)using bookdown package from R-studio. During this effort , following features where a big boost in productivity
Create a separate bib file
Include the citation anywhere in rmarkdown file, from figure caption to text, just by calling a [@bibkey] was a significant boost in productivity
Generate a section at the bottom of rendered html with all the cited reference
I would love to find a solution which can let me do something similar with nbdev. Even though it might have some additional pre-processing steps which are outside nbdev scope. Any suggestions on how to go about building something similar or adopting an existing solution would be highly appreciated.
Since I am new to jekyll world, exploring these options is going to take some time. I have reviewed following things so far :-
Idea 1: Starting from scratch and learning basics of jekyll template and jekyll plugins. Online recommendations include following
Jekyll scholar is not included on github pages so either use it to build _site locally or use a service which can let you build the same. Netlify seems to have worked for people. I prefer building _site from netlify deploy settings but havenot succeeded in doing the same so far.
Building with jekyll locally on windows is giving me a lot of pain. I could use linux VM to learn the basics which I think I should do .But I want to figure out a windows solution first as most of my team is on windows machine with GPU.[GPU wonât work on VM side]
Idea 2: Hack a command which can do some preprocessing before using nbdev_build_docs
Looking at generated html from nbdev_build_docs in my docs folder; I find html has been stripped of all the metadata which includes metadata added by from cite2c plugin from jupyter; which means whatever I do these will not work
Read a bit of source code to figure out what is happening in notebook2html function. I am still not certain of all the things HTMLParsers are doing . This would probably require much more effort.
I like how I can dynamically see references getting included by cite2c plugin in rendering in jupyter notebook. In above approach there might be some hack to read metadata -> find all âciteâ tags using regex -> do some external call cite2proc-js -> replace string output -> call nbdev_build_docs. However this would require much more time to explore which I currently lack.
I think I have now spend more time on this then I intended. I will keep learning & exploring on and off whenever I can afford some more time.
Hosting site on netlify, So Git push works. [Donât have to build locally. I am still struggling with viewing local docs , sidebar links not working at all]
However, what if you want a single quote in your footnote? There is not an easy way to escape that. Fortunately, you can use the special HTML character ' (you must keep the semicolon!). For example, you can include a single quote like this:
This adds a linked superscript {% fn 20 %}
{{ 'This is the actual footnote; with a [link](www.github.com) as well! and a single quote ' too!' | fndetail: 20 }}
During this effort , following features where a big boost in productivity
Create a separate bib file
Include the citation anywhere in rmarkdown file, from figure caption to text, just by calling a [@bibkey] was a significant boost in productivity
Generate a section at the bottom of rendered html with all the cited reference
I generate not only blog post from the notebook, but also latex source for my thesis. Making this two things separately (nicely formatted blog and nicely formatted latex->pdf) creates too much burden.
@ducha-aiki thanks for sharing. Havenât thought about multiple target outputs. It looks like you may have a plan on how to do that via nbdev, so look forward to watching that thread.
Yeah I can help with that. Why donât you submit a PR to nbdev? Looks like a reasonable set of features to me? Based on my experience, this is something that has a reasonable probability of being merged. ( @sgugger of course will review)
Once that is done, I can bump all the official images for fastpages to include the changes.
Sure. The reason I havenât submitted PR yet is because I am following the contributing guide)))
âOnce your approach has been discussed and confirmed on the forum, you are welcome to push a PR, including a complete description of the new feature and an example of how itâs used. Be sure to document your code in the notabook.â
I guess another thing you want to check for is there are no collisions with other features, somehow. I have some suspicion that this could collide with other magic that handles links, But I donât think it will - nothing seems off to me, but just asking to make sure
Following up on this, a few months later: @hamelsmu Is there now any consensus for how can we best (i.e. most easily) incorporate citations from a bibtex file into our Fastpages blogs? Iâm fine with trying to plug in jekyll-scholar, just wasnât sure if this was still a âyouâre on your ownâ kind of thing or if itâs now been âstandardizedâ somehow. (I realize such a feature is probably beyond the scope of your original vision for this increasingly successful blogging platform! )
Btw, Iâm enjoying writing âpure Markdownâ posts using Typora (which I find to be a âbeautifulâ editor), rather than writing in Jupyter. Alternatively, I could switch to doing these âMarkdown-onlyâ posts in just one big Jupyter cell and then use @ducha-aikiâs method. ButâŚthat would not be my preferred method.
(If it ends up being that Iâd need to run some sort of manual script after editing, such that the build is not fully automated, Iâm actually ok with that.)