Using dataview for generating citations

Hello, I am an academic researcher using Obsidian.

Currently, I have a note for each article/book, and have used [[Links]] to link Topics (healthcare, semiotics, psychology) and also Author (so that in graph view, I can highlight the node for an author and see all the works from them that I have read). I’d like not to lose this linking system.

Now, I am moving towards Dataview and Citations. I would like to be able to create a text block for each note. I want this text block to match the format of a bibtex entry, so when I write manuscripts I can just copy text from the text block into my LaTeX editor. Either:

Here is an example text block I would like to generate

  1. This Citation Text can either be stored in a separate file (e.g. a Dataview query that generates the text format for all my files and stores them in one note, almost like a citation index)

  2. OR each citation can be a text somewhere in the note for each Book

How can I go about doing this?

Reddit thread:

Interesting! As another academic user who writes in LaTeX/BibTeX, generating correct BibTeX sounds like it could be tricky. A few additional questions to clarify a bit more what you are trying to do:

Could you share an example of one of your article or book notes so that we can see what fields you have set up?
Do you have an external reference manager (e.g. Zotero) or are you essentially using Obsidian as a reference manager? Or, perhaps another way to ask this, how do you generate citations currently? A software program? A tool on a website? Memorized rules of what fields go in which bibtex types? …?

Thank you!
I’ve unfortunately just been formatting the BiBTeX fields in a Obsidian code block. Here’s an example note heading (below the — is just note content):

I’m definitely willing to modify the metadata/note header set up for efficient BibTexing, here’s how it is now.

I’d like to autopopulate the title, author, and year fields based on the existing note (I can manually fill in publishers/journals). I’d also like the TeX type (here’s, it’s @Book) to autopopulate based on the Type field above.

Because most of my notes are books or articles, I’ve just memorized the BiBTeX types. I plan on copying the code block into an Overleaf document to generate the bibliography for my manuscripts.

Thank you, this makes it a lot clearer!

Wow! Well then you know what fields you need to generate, I guess! My memory from fixing BibTeX errors in a manuscript is that there were some challenges around capitalization in titles or author names, as well as unexpected-to-bibtex characters in those fields, and I have since forgotten all of the tricks for fixing those up, so I would definitely lean towards having software generate the bibtex for me. But since you are already doing it by hand…

Huh, I just learned that LaTeX code blocks have a handy “Copy” button in reading mode that seems to preserve the spaces and linebreaks properly! So it sounds like you may want to just generate this codeblock programmatically, rather than using one of the existing dataview output formats such as a list or table? That sounds like it is probably going to require dataviewjs.

Fun fact: if your dataviewjs codeblock begins and ends with more than 3 backticks (I tried with 4) then you can nest the construction of a codeblock of 3 backticks inside.

dv.span("```latex\[email protected]\n    indented field\n```\n");

gave me output in Reading Mode that looks equivalent to writing the latex codeblook with that content, for example.

My guess is that you would want to construct your entries line by line into an array, and then .join('\n') them with linebreaks at the end. So if you had let entry = ["@" + dv.current().type.toUpper() + "={" + ...]; making your first line you could do something like

entry.push(`    title = {${dv.current().file.name}}`);

to add the line with the title. (Warning: any of this code probably has typos in it; I ran out of time to both test and write this up.) But hopefully you get the idea about different ways you could combine your dataview and your handcrafting of bibtex.

To repeat, I would not recommend this route because it seems really tricky to get right! Each line is going to have its own challenges: constructing your citekey, getting the author filenames through the links, special characters, etc. But it does seem possible if you want to spend some hours on it. I would look into whether there are any existing plugins or libraries or tools that you can use to help with all the string manipulation to produce valid bibtex. Maybe others will have concrete ideas of plugins or tools that can help!

Definitely do share what you end up with!

Here’s the current implementation. Any suggestions for having the output in a code block?


Nice, inline dataview is definitely less messy than generating it all in Javascript.

Small improvement: If you still have a Type:: Book field, you can put @=upper(this.type) at the beginning I think.
Comment: for keys in your YAML you only want one colon after the key, while after the YAML you need 2 (as you successfully have with Author).

Making a codeblock with the output
I think you will need to transform your Dataview into dataviewjs. this becomes dv.current() and the thing I said above about upper( becomes more like the version I had in my first post. Then since your whole thing is in a codeblock the single backticks and = around your dataview statements become ${ in front and } at the end (no backticks in any of that). If copy-pasting from the below, get rid of the lines with 5 backticks in a row before filling in the ...:

````dataviewjs
dv.span("```latex" + `
@BOOK{${dv.current().bID},
    title={${dv.current().file.name}}
    author=...
},\n` + "```");
````

I found it much easier to copy the block from Reading Mode, and an external text editor seemed to recognize the pasted output as BibTeX, but only if I took out the = sign after @BOOK. Did not test specifically on Overleaf.

Good luck!

Thank you, this looks almost perfect. Two questions:

  1. Author field: My author field is currently set up as a link, so I can see all works by a given Author in my database. How can I change this so the format in Dataview is consistent with BibTex? I’d like it to displace {Foucault, Michel} without the [[ ]]

Note: This would have to be able to juggle multiple authors (for example: [[Foucault, Michel]] and [[Deleuze, Gilles]] )
I think the simplest solution is a .replace() function that removes [[ ]], if some sort of analog exists here.

I’m also trying to generate the bID field automatically to be LastNameYear for the first author, any suggestions for doing that?

The Date is only the year (1963) for this file, but could be 1963-12-13 for example (YYYY or YYYY-MM-DD).

I do not remember what the right bibtex syntax is for multiple authors. But you can de-link in a couple ways. Assuming you want to use the filename of the author’s file I think you can just do (for a single author) dv.current().Author.file.name which pulls the file.name field out of the page you linked to. Doing that means you do not have to check for display text on the link as you would with replace. The remaining challenge is to determine whether there are multiple authors and and if so Author.map(a => a.file.name ).join("...") where ... is whatever syntax one uses between multiple author names in bibtex.

See if you can call dv.current().Date.format("YYYY")? Or if it says it is not a date, try the substring method if all your dates begin with the year?

No idea how to do the last-name bit. Some authors have multiple last names, right?

Good luck!

All dates will begin with a year. How do I call the substring method?

Substring [first 4 digits] should be suitable

Topic

Summary

1.How to get sBibTex_citations and display it in the current file?
( Look at DVJS20_output_this_BibTex_citations_shorter )

1.1 How to get a_Author each of which is a string from page.Author?
( Look at Step M23 )


2.How to get s_Year where the format of page.Year is YYYY or YYYY-MM-DD such as :
---
Year: 1963
---

or

---
Year: 1963-12-13
---

( Look at Inline DQL: get s_Year )


3.How to get s_Author where page.Author is a link or a list of links such as :
Author:: [[Foucault, Michel]]

or

Author:: [[Foucault, Michel]], [[Deleuze, Gilles]]

( Look at DVJS30_output_this_s_Author )


4.How to get s_bID where page.bID is s_Author_LastName + s_Year ? ( Look at DVJS40_output_this_s_bID )

Input

Summary

Requirements

  • Author field: My author field is currently set up as a link, so I can see all works by a given Author in my database. How can I change this so the format in Dataview is consistent with BibTex? I’d like it to displace {Foucault, Michel} without the [[ ]]

Note: This would have to be able to juggle multiple authors (for example: [[Foucault, Michel]] and [[Deleuze, Gilles]] )
I think the simplest solution is a .replace() function that removes [[ ]], if some sort of analog exists here.


  • Year field: The Date is only the year (1963) for this file, but could be 1963-12-13 for example (YYYY or YYYY-MM-DD).

All dates will begin with a year. How do I call the substring method?


  • bID field: I’m also trying to generate the bID field automatically to be LastNameYear for the first author, any suggestions for doing that?

dictionary files

  • filename : dic_20190301
---
Date: 2019-03-01
bID: Foucault1963
Year: 1963-12-13
Publisher: Routledge
Address: United Kingdom
---

Author:: [[Foucault, Michel]], [[Deleuze, Gilles]]
Type:: Book
Topics:: [[Biopower]], [[Healthcare]]
Tags:: #Philosophy
Status:: Fresh

  • filename : dic_20190306
---
Date: 2019-03-01
bID: Deleuze1972
Year: 1972
Publisher: Routledge
Address: United Kingdom
---

Author:: [[Deleuze, Gilles]]
Type:: Book
Topics:: [[Biopower]], [[Healthcare]]
Tags:: #Philosophy
Status:: Fresh


  • filename : Deleuze, Gilles
Deleuze, Gilles is a philosopher.

  • filename : Foucault, Michel (not exist)


Metadata: used by the current page code

Summary
---
number headings: first-level 2, max 6, contents ^toc, _.1.1.
Date: 2019-03-01
bID: Foucault1963
Year: 1963-12-30
Publisher: Routledge
Address: United Kingdom
---

Author:: [[Foucault, Michel]], [[Deleuze, Gilles]]
Type:: Book
Topics:: [[Biopower]], [[Healthcare]]
Tags:: #Philosophy
Status:: Fresh

original design

@BOOK={=this.bID,
     Title = {=this.file.name}
     Author = {=this.Author}
     Year = {=this.Year}
     Publisher = {=this.Publisher}
     Address = {=this.Address}
}

expected result

@BOOK={Foucault1963},
     Title = {20220721_BiBTeX}
     Author = {Foucault, Michel and Deleuze, Gilles}
     Year = {1963}
     Publisher = {Routledge}
     Address = {United Kingdom}
}

Notes

  • Author=Foucault, Michel and Deleuze, Gilles
  • Field and entry names are case insensitive.So there is no difference between author, Author, AUTHOR.

Solution: Inline

Summary

Inline DQL: get s_Year

step 1: get dt_Year

dt_Year== choice( typeof(this.Year) != "date", date(this.Year+ "-12-30"), this.Year )
//=>12 30, 1963 (a date)

step 2: get s_Year

s_Year== dateformat(choice( typeof(this.Year) != "date", date(this.Year+ "-12-30"), this.Year ), "yyyy")
//=>“1963”

Inline DVJS: get s_Author

To understand steps:

To look at: DVJS30_output_this_s_Author

To use code:

To copy from: inDVJS10_output_this_s_Author

Inline DVJS: get s_bID

To understand steps:

To look at: DVJS40_output_this_s_bID

To use code:

To copy from: inDVJS20_output_this_s_bID


Solution: Main

Summary_wikiLink
F1_R1      `rest_field`          Type         path
Link       [[wikiLinkNotExist]]  Hash(Link)   wikiLinkNotExist
Link       [[wikiLinkExist]]     Hash(Link)   100_Project/wikiLinkExist.md

DVJS10_output_this_BibTex_citations

Summary

Main DVJS

Code Name deal with data type Purposes Remark
DVJS10_output_this_BibTex_citations 1.a_Author:
1.1 NotLists, Lists;
1.2 Hash(Link), AoH(Array of hashes)
2.s_Year: number, date
0.require metadata YAML+DVIF
1.get a_Author + s_Author
2.get s_Year
3.get s_bID
4.define sBibTex_citations
5.output it

Code DVJS10_output_this_BibTex_citations

Summary_code
title: DVJS10_output_this_BibTex_citations =>0.require metadata YAML+DVIF 1.get  + s_Author 2.get s_Year 3.get s_bID 4.define sBibTex_citations 5.output it
collapse: close
icon: 
color: 
```dataviewjs
// M02. Require the print function :
// #####################################################################
// version : 2022-05-01 v1.00 Justdoitcc
function print(...aArgs){
    let aText=[...aArgs];
    let sTextJoined=aText.join('').replace(/[ ]/g,'&nbsp').replace(/(\r\n|\r|\n)/g, '<br>');
    dv.el("span", sTextJoined);
    return true;
}

// M11. define pages: this current page
// #####################################################################
let pages = dv.current();


// M21. define a_Author: array of hashes(links)
// #####################################################################
let a_Author = [];
if (!dv.isArray(pages.Author)) {
    a_Author = [pages.Author];
} else {
    a_Author = pages.Author;
}

// M21.DEB01 Debug Output a_Author:
// #####################################################################
//print("The following is the content of the `a_Author`.\n");
//print(JSON.stringify(a_Author, null, 2), "\n");


// CASE 1: [[wikiLinkNotExist]]=>Hash(Link).path: not endwith ".md"
// #####################################################################
// The following is the content of the a_Author.
// [
//   {
//     "path": "Foucault, Michel",
//     "type": "file",
//     "embed": false
//   },
//   {
//     "path": "Deleuze, Gilles",
//     "type": "file",
//     "embed": false
//   }
// ]


// CASE 2: [[wikiLinkExist]]=>Hash(Link).path: endwith ".md"
// #####################################################################
// The following is the content of the a_Author.
// [
//     {
//       "path": "100_Project/02_dataview/Q08_BiBTeX/Q08_BiBTeX/04/Foucault, Michel.md",
//       "type": "file",
//       "embed": false
//     },
//     {
//       "path": "100_Project/02_dataview/Q08_BiBTeX/Q08_BiBTeX/04/Deleuze, Gilles.md",
//       "type": "file",
//       "embed": false
//     }
// ]



// M23. get a_Author: array of strings
// #####################################################################
// CASE 1: When the file does not exist : get each path of a_Author
// CASE 2: When the file exists: get each file.name of a_Author
a_Author = a_Author.map((hLink) => {
    // M17.EL01 CASE 1:  
    // [[wikiLinkNotExist]]=>Hash(Link).path:wikiLinkNotExist
    if (!dv.func.endswith(hLink.path, ".md")) {
        return hLink.path; //=>"Foucault, Michel"
    } else {
        // M17.EL03 CASE 2:
        // [[wikiLinkExist]]=>Hash(Link).path:100_Project/wikiLinkExist.md
        return dv.page(hLink.path).file.name;//=>"Foucault, Michel"
    }
});


// M23.DEB01 Debug Output a_Author:
// #####################################################################
// [
//     "Foucault, Michel",
//     "Deleuze, Gilles"
// ]


// #####################################################################
// M25. get s_Author:  Foucault, Michel and Deleuze, Gilles
// #####################################################################
let s_Author = "";
if (a_Author.length === 1) {
    s_Author = a_Author[0];
} else {
    s_Author = a_Author.join(" and ");//=>Foucault, Michel and Deleuze, Gilles
}


// M31. get dt_Year : transform idt_Year into a `date`
// #####################################################################
let idt_Year = pages.Year;//=> pages.Year = 1963 or 1963-12-30
let dt_Year = dv.func.choice(
    dv.func.typeof(idt_Year) !== "date",
    dv.date(idt_Year + "-12-30"),
    idt_Year
);
//=>12 30, 1963 (a date)


// #####################################################################
// M33. get s_Year: dateformat dt_Year (`date`) to a s_Year (`string`)
// #####################################################################
let s_Year = dt_Year.toFormat("yyyy"); //=>"1963"


// #####################################################################
// M41. get s_bID: s_Author_LastName + s_Year
// #####################################################################
let s_Author_LastName = dv.func.split(a_Author[0], ",")[0] ;
let s_bID = s_Author_LastName + s_Year;


// M61. define sBibTex_citations:
// #####################################################################
// Requirement:
// ```
// @BOOK={=this.bID,
//     &emsp;Title = {=this.file.name}
//     &emsp;Author = {=this.Author}
//     &emsp;Year = {=this.Year}
//     &emsp;Publisher = {=this.Publisher}
//     &emsp;Address = {=this.Address}
// }
// ```

let sBibTex_citations = `
<pre><code>
@BOOK={${s_bID}},
    &emsp;Title = {${pages.file.name}}
    &emsp;Author = {${s_Author}}
    &emsp;Year = {${s_Year}}
    &emsp;Publisher = {${pages.Publisher}}
    &emsp;Address = {${pages.Address}}
}
</code></pre>
`

// M71. Output sBibTex_citations:
// #####################################################################
dv.span(sBibTex_citations);



```

Screenshots(DVJS10)


@BOOK={Foucault1963},
     Title = {20220721_BiBTeX}
     Author = {Foucault, Michel and Deleuze, Gilles}
     Year = {1963}
     Publisher = {Routledge}
     Address = {United Kingdom}
}

DVJS20_output_this_BibTex_citations_shorter : final

Summary

Main DVJS

Code Name deal with data type Purposes Remark
DVJS20_output_this_BibTex_citations_shorter 1.a_Author:
1.1 NotLists, Lists;
1.2 Hash(Link), AoH(Array of hashes)
2.s_Year: number, date
0.require metadata YAML+DVIF
1.get a_Author + s_Author
2.get s_Year
3.get s_bID
4.define sBibTex_citations
5.output it
1.The code is copied from DVJS10_output_this_BibTex_citations
2.The comments which are out of use are removed.
3.To refactor Step M21 an M23
4.It is the final verson.

Code DVJS20_output_this_BibTex_citations_shorter

Summary_code
title: DVJS20_output_this_BibTex_citations_shorter =>0.require metadata YAML+DVIF 1.get a_Author + s_Author 2.get s_Year 3.get s_bID 4.define sBibTex_citations 5.output it
collapse: close
icon: 
color: 
```dataviewjs
// M11. define pages: this current page
// #####################################################################
let pages = dv.current();


// M21. define a_Author: array of hashes(links)
// #####################################################################
// dv.array():Convert a given value or array into a Dataview data array. If the value is already a data array, returns it unchanged.
let a_Author = dv.array(pages.Author);


// M23. get a_Author: array of strings
// #####################################################################
// CASE 1: When the file does not exist : get each path of a_Author
// Left  : [[wikiLinkNotExist]]=>Hash(Link).path:wikiLinkNotExist
// CASE 2: When the file exists: get each file.name of a_Author
// Right : [[wikiLinkExist]]=>Hash(Link).path:100_Project/wikiLinkExist.md
a_Author = a_Author.map(
    (hLink) =>
        (!dv.func.endswith(hLink.path, ".md") && hLink.path) ||
        dv.page(hLink.path).file.name
);


// #####################################################################
// M25. get s_Author:  Foucault, Michel and Deleuze, Gilles
// #####################################################################
let s_Author = "";
if (a_Author.length === 1) {
    s_Author = a_Author[0];
} else {
    s_Author = a_Author.join(" and ");//=>Foucault, Michel and Deleuze, Gilles
}


// M31. get dt_Year : transform idt_Year into a `date`
// #####################################################################
let idt_Year = pages.Year;//=> pages.Year = 1963 or 1963-12-30
let dt_Year = dv.func.choice(
    dv.func.typeof(idt_Year) !== "date",
    dv.date(idt_Year + "-12-30"),
    idt_Year
);
//=>12 30, 1963 (a date)


// #####################################################################
// M33. get s_Year: dateformat dt_Year (`date`) to a s_Year (`string`)
// #####################################################################
let s_Year = dt_Year.toFormat("yyyy"); //=>"1963"


// #####################################################################
// M41. get s_bID: s_Author_LastName + s_Year
// #####################################################################
let s_Author_LastName = dv.func.split(a_Author[0], ",")[0] ;
let s_bID = s_Author_LastName + s_Year;


// M61. define sBibTex_citations:
// #####################################################################
// Requirement:
// ```
// @BOOK={=this.bID,
//     &emsp;Title = {=this.file.name}
//     &emsp;Author = {=this.Author}
//     &emsp;Year = {=this.Year}
//     &emsp;Publisher = {=this.Publisher}
//     &emsp;Address = {=this.Address}
// }
// ```

let sBibTex_citations = `
<pre><code>
@BOOK={${s_bID}},
    &emsp;Title = {${pages.file.name}}
    &emsp;Author = {${s_Author}}
    &emsp;Year = {${s_Year}}
    &emsp;Publisher = {${pages.Publisher}}
    &emsp;Address = {${pages.Address}}
}
</code></pre>
`

// M71. Output sBibTex_citations:
// #####################################################################
dv.span(sBibTex_citations);



```

Screenshots(DVJS20)


@BOOK={Foucault1963},
     Title = {20220721_BiBTeX}
     Author = {Foucault, Michel and Deleuze, Gilles}
     Year = {1963}
     Publisher = {Routledge}
     Address = {United Kingdom}
}

DVJS30_output_this_s_Author

Summary

Main DVJS

Code Name deal with data type Purposes Remark
DVJS30_output_this_s_Author 1.a_Author:
1.1 NotLists, Lists;
1.2 Hash(Link), AoH(Array of hashes)
0.require metadata YAML+DVIF
1.get a_Author
2.get s_Author
3.output s_Author
1.The comments which are out of use are removed.
2.The code is copied from DVJS20_output_this_BibTex_citations_shorter
3.To remove Step (>=M30)
4.To add Step M91
5.The code is used to be converted to inline DVJS.

Code DVJS30_output_this_s_Author

Summary_code
title: DVJS30_output_this_s_Author =>0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.output s_Author
collapse: close
icon: 
color: 
```dataviewjs
// M23. get a_Author: array of hashes(links)==>array of strings  (M11+M21+M23)
// #####################################################################
let a_Author = dv.array(dv.current().Author).map(
    (hLink) =>
        (!dv.func.endswith(hLink.path, ".md") && hLink.path) ||
        dv.page(hLink.path).file.name
);


// #####################################################################
// M25. get s_Author:  Foucault, Michel and Deleuze, Gilles
// #####################################################################
let s_Author = "";
if (a_Author.length === 1) {
    s_Author = a_Author[0];
} else {
    s_Author = a_Author.join(" and ");
}


// M91. Output s_Author:
// #####################################################################
dv.span(s_Author);


```

Screenshots(DVJS30)

//=>Foucault, Michel and Deleuze, Gilles


inDVJS10_output_this_s_Author

Summary

Main Inline DVJS

Code Name deal with data type Purposes Remark
inDVJS10_output_this_s_Author 1.a_Author:
1.1 NotLists, Lists;
1.2 Hash(Link), AoH(Array of hashes)
0.require metadata YAML+DVIF
1.get a_Author
2.get s_Author
4.output s_Author
1.It is the same as DVJS30_output_this_s_Author.
2.DVJS30_output_this_s_Author is simplified to be an Inline DVJS.

Notes

Notes:
0.copy DVJS30_output_this_s_Author to code_tmp
1.Steps: (M11+M21+M23)+M25+(M91)
2.At Step M25: To remove let s_Author = "";
3.At Step M25: To remove s_Author =
4.At Step M91: To remove dv.span(s_Author);
5.At Step M25: To replace a_Author as the content of a_Author which is defined at Step M23
6.At Step M23: To remove the content which is defined at Step M23
7.At Step M25: To copy the content into an Inline DVJS expression.
8.An Inline DVJS is finishd!


Code inDVJS10_output_this_s_Author

Summary_code

s_Author=$= if ( dv .array(dv.current().Author) .map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name ).length === 1 ) { dv .array(dv.current().Author) .map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name )[0]; } else { dv.array(dv.current().Author) .map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name ) .join("and"); }


Screenshots(inDVJS10)

//=>Foucault, MichelandDeleuze, Gilles


DVJS40_output_this_s_bID

Summary

Main DVJS

Code Name deal with data type Purposes Remark
DVJS40_output_this_s_bID 1.a_Author:
1.1 NotLists, Lists;
1.2 Hash(Link), AoH(Array of hashes)
2.s_Year: number, date
0.require metadata YAML+DVIF
1.get a_Author
2.get s_Author
3.get s_Year
4.get s_bID
5.output s_bID
1.The comments which are out of use are removed.
2.The code is copied from DVJS20_output_this_BibTex_citations_shorter
3.To remove Step M25, M61 and M71
4.To add Step M91
5.The code is used to be converted to inline DVJS.

Code DVJS40_output_this_s_bID

Summary_code
title: DVJS40_output_this_s_bID =>0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.get s_Year 4.get s_bID 5.output s_bID
collapse: close
icon: 
color: 
```dataviewjs
// M23. get a_Author: array of hashes(links)==>array of strings  (M11+M21+M23)
// #####################################################################
let a_Author = dv.array(dv.current().Author).map(
    (hLink) =>
        (!dv.func.endswith(hLink.path, ".md") && hLink.path) ||
        dv.page(hLink.path).file.name
);


// #####################################################################
// M33. get s_Year: dateformat dt_Year (`date`) to a s_Year (`string`) (M31+M33)
// #####################################################################
let s_Year = dv.func.choice(
    dv.func.typeof(dv.current().Year) !== "date",
    dv.date(dv.current().Year + "-12-30"),
    dv.current().Year
).toFormat("yyyy"); //=>"1963"


// M41. get s_Author_LastName:
// #####################################################################
let s_Author_LastName = dv.func.split(a_Author[0], ",")[0] ;


// #####################################################################
// M51. get s_bID: s_Author_LastName + s_Year
// #####################################################################
let s_bID = s_Author_LastName + s_Year;


// M91. Output s_bID:
// #####################################################################
dv.span(s_bID);


```

Screenshots(DVJS40)

//=>Foucault1963


inDVJS20_output_this_s_bID

Summary

Main Inline DVJS

Code Name deal with data type Purposes Remark
inDVJS20_output_this_s_bID 1.a_Author:
1.1 NotLists, Lists;
1.2 Hash(Link), AoH(Array of hashes)
2.s_Year: number, date
0.require metadata YAML+DVIF
1.get a_Author
2.get s_Author
3.get s_Year
4.get s_bID
5.output s_bID
1.It is the same as DVJS40_output_this_s_bID.
2.DVJS40_output_this_s_bID is simplified to be an Inline DVJS.

Notes

Notes:
0.copy DVJS40_output_this_s_bID to code_tmp
1.Step M51: let s_bID = s_Author_LastName + s_Year;
Part A(Left): To simplify s_Author_LastName
10.At Step M41: To replace a_Author as the content of a_Author which is defined at Step M23
11.At Step M51: To replace s_Author_LastName as the content of s_Author_LastName which is defined at Step M41
12.Part A(Left) is finoshed.
Part B(Right): To replace s_Year
21.At Step M51: To replace s_Year as the content of s_Year which is defined at Step M33
22.Part B(Right) is finoshed.
31.At Step M51: To copy the content between let s_bID = and ; into an Inline DVJS expression.
32.An Inline DVJS is finishd!

Code inDVJS20_output_this_s_bID

Summary_code

s_bID=$= dv.func.split(dv.array(dv.current().Author).map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name )[0], ",")[0] + dv.func.choice( dv.func.typeof(dv.current().Year) !== "date", dv.date(dv.current().Year + "-12-30"), dv.current().Year ).toFormat("yyyy")


Screenshots(inDVJS20)

//=>Foucault1963


1 Like