Zotero - Details on Field Codes/Bookmarks/Switch to Different Word Processor

Are there any details on how the field codes/bookmarks or switch to different word processor options are implemented? I'm happy if you point me to right spot to look in the github code.

For clarity, my ultimate goal is to use zotero with noamross/redoc (github repo), which is a way to create a Rmarkdown document that can be converted into a word document that retains markers for the various code blocks, such that it can be converted back to Rmd even after editing. It makes collaboration much better since no one who isn't already invested in all the technologies (i.e. your thesis supervisor) has to learn how to use different tools just so they can work with you, but it's still possible to take advantage of all of the nice literate programming tools available through R and Rmarkdown. I think there would be a huge advantage if the community was able to produce reports using reproducible literate programming methods with access to some sort of reference manager.

I've tested field codes/bookmarks/ZOTERO_EXPORTED_DOCUMENT in a simple document consisting of a single citation. It's easy to paste these into another (word) document and see that the other document imports the references well. The problems arise when you take a round trip through markdown.

Using pandoc: `pandoc -t docx+styles+empty_paragraphs doc_with_citation.docx -o doc.md`

- Field codes: I have no idea how to make this information accessible to pandoc
- Bookmarks: Pandoc does this weird thing where it deletes bookmarks if they aren't also linked to , so I created links to the bookmarks, but that didn't help when I converted the document back to docx
- ZOTERO_EXPORTED_DOCUMENT: looks the most promising and looks like it converts well to md and then back to docx. However, hitting "refresh" in the zotero toolbar says there are no citations to import. I've tried making the ZOTERO_ITEM_CSL (probably got that name slightly wrong) and the footer into links to https://www.zotero.org since that's what they were in the original document, but it seems like I'm still missing something.

I'm also aware of the RTF/ODT scan option --> that would be a good solution if noamross/redoc worked with OpenOffice, but it doesn't.

Does anyone know anything or know where these are documented/in the code?

Thanks a lot!
  • In this case, let pandoc handle the citations in the Markdown -> conversion. If you want citations to be converted back to citations when you dedoc back to Markdown, use the citationwrap() function. See ?make_wrapper()
  • Thanks @bwiernik!

    This looks super interesting. I definitely need to convert a bunch of citations but I think it should work for what I need.

    Since you seem familiar with `redoc`, I will also ask a follow-up question. Do you know if there is a good way to get a reversible document workflow with figures? If I try to roll my own with direct insertion of images I can get `redoc` to play nicely, but then I don't have a way to auto-generate a `\tableoffigures` either via Rmd or Word itself. If I use something like `pandoc-crossref` then I can use `\tableoffigures` but neither the generated table or the figures themselves play well with `redoc` in that case.

    It seems like `make_wrapper` could be useful for this, but if I try hacky things like

    +======example.Rmd=========
    ---
    output_format: redoc::redoc:
    pandoc_args:
    - -F
    - pandoc-crossref
    ---
    ```{r echo=FALSE, results="asis"}
    cat("![Figure legend](Figure_1.png){#fig:fig1}
    ```

    To force generation of an R codeblock, this doesn't get reversed well and the code block gets lost
  • Output of code blocks (and citations) are all automatically handled by redoc. Run:

    redoc::dedoc(redoc::redoc_example_edited_docx())

    And see. You are overthinking this I think. redoc already has all of these things worked out for you (that’s the point of it).
  • I would love it if I was overthinking things. I feel like I've tried all the reasonable things, but if you can point out what I've missed it would make my day since I've been hitting my head against this for a bit now.

    example.Rmd:
    ---
    output:
    redoc::redoc:
    pandoc_args: ["-F", "pandoc-crossref"]
    ---



    # Some Title

    \listoffigures

    ![Figure 1](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png){#fig:fig1}

    Now I would like to reference [@fig:fig1]

    ```{r echo=FALSE, results='asis'}
    # Useful hack, but the codeblock is not properly preserved
    # Possibly custom-style gets lost
    cat("![Figure 2](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png){#fig:fig2}")
    ```

    Now I would like to reference [@fig:fig2]


    ```{r echo=FALSE}
    plot(1:10,10:1)
    ```
    Figure 3 Caption goes here and the listoffigures gets messed up because of the div inserted by the code chunk


    Now I would like to reference [@fig:fig3]

    ## Maybe if I don't use pandoc-crossref?

    ```{r echo=FALSE, fig.cap="No figure label for this one"}
    plot(1:10,20:11)
    ```

    If I just insert an image, it also doesn't get preserved by redoc ![Regular alt-text](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png)


    Actually the only way to preserve a sane image link is to create a code block.

    ```{r echo=FALSE, results='asis'}
    cat("![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png)")
    ```

    And it doesn't even work if you put in any alt-text

    ```{r echo=FALSE, results='asis'}
    cat("![This is alt text](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png)")
    ```
    And the dedoc of the docx produced by `render`ing the above `example.Rmd`:

    <!-- originally line 7
    \listoffigures
    -->

    ---
    output:
    redoc::redoc:
    pandoc_args:
    - -F
    - pandoc-crossref
    ---
    Some Title
    ==========

    List of Figures
    ===============

    <!-- originally line 17
    ```{r echo=FALSE, results='asis'}
    # Useful hack, but the codeblock is not properly preserved
    # Possibly custom-style gets lost
    cat("![Figure 2](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png){#fig:fig2}")
    ```
    -->

    1. Figure 1
    2. Figure 2
    3.
    4. Figure 3 Caption goes here and the listoffigures gets messed up because of
    the div inserted by the code chunk

    ![Figure 1: Figure 1](media/rId22.png){width="0.8888888888888888in"
    height="1.1944444444444444in"}

    Figure 1: Figure 1

    Now I would like to reference [@fig:fig1]

    ![Figure 2: Figure 2](media/rId22.png){width="0.8888888888888888in"
    height="1.1944444444444444in"}

    Figure 2: Figure 2

    Now I would like to reference [@fig:fig2]

    ```{r echo=FALSE}
    plot(1:10,10:1)
    ```
    <!-- originally line 30
    ```{r echo=FALSE, fig.cap="No figure label for this one"}
    plot(1:10,20:11)
    ```
    -->

    Figure 3: Figure 3 Caption goes here and the listoffigures gets messed up
    because of the div inserted by the code chunk.

    Now I would like to reference [@fig:fig3]

    Maybe if I don't use pandoc-crossref?
    -------------------------------------

    ![No figure label for this one](media/rId33.png){width="5.833333333333333in"
    height="5.833333333333333in"}

    No figure label for this one

    If I just insert an image, it also doesn't get preserved by redoc ![Regular
    alt-text](media/rId22.png){width="0.8888888888888888in"
    height="1.1944444444444444in"}

    Actually the only way to preserve a sane image link is to create a code block.

    ```{r echo=FALSE, results='asis'}
    cat("![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png)")
    ```
    <!-- originally line 41
    ```{r echo=FALSE, results='asis'}
    cat("![This is alt text](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/64px-Commons-logo.svg.png)")
    ```
    -->

    And it doesn't even work if you put in any alt-text

    ![This is alt text](media/rId22.png){width="0.8888888888888888in"
    height="1.1944444444444444in"}

    This is alt text
  • Realized I forgot to tag you in the last reply @bwiernik. (thread at https://forums.zotero.org/discussion/82495/zotero-details-on-field-codes-bookmarks-switch-to-different-word-processor in case this is in your inbox)

    I put up a minimal working example showing the various ways I have tried to insert figures in what I thought were sane ways and showing how redoc completely fails to deal with them well when dedocing.

    From my investigations, it seems like redoc doesn't want to play well with images in general, but also not with features from pandoc-crossref such as \listoffigures

    If you see something obvious that I am doing wrong, I'd love it if you can point me in the right direction, but I also know that this has probably already taken up too much of a stranger's time and kindness.

    Cheers!
  • (You don't need to tag someone for a normal reply. A notification will be sent out to all thread participants for the first comment since they last visited the thread, which by definition includes the first response to someone's comment. And you don't need to link to the thread, which is included in the email.)
  • Can you post a minimal reproducible example Rmd at gist.github.com and link here?
  • Pasted the code from the above example.Rmd into a gist:

    https://gist.github.com/erikli/f5676f7adb87c27bfe48acc616a74b03

    What I see when I rmarkdown::render() and then redoc::dedoc() is here:

    https://gist.github.com/erikli/9fb1bd17c3e0d389d18abf278fe509f2
Sign In or Register to comment.