How to display one bibliography in different styles according to the language which is used in the references using CSL and citeproc? - pandoc

I would like to ask a question related to an ongoing issue in the GitHub repository of jgm/citeproc here, since my question may come to be out of scope of the original issue.
I'm trying to apply an approach proposed in a comment on the thread on GitHub to a csl file so that I can display English references and non-English ones (Chinese lang-zh, here) in different layouts according to their language. That is, when citeproc finds that a bib entry of a .bib file contains a csl's variable (say lang-zh), that bib entry is displayed in a layout that is specified in the csl's if-statement as shown below:
<citation>
...
<layout>
<choose>
<if variable="lang-zh">
<!--
Multibyte comma as a deliminater for non-English references
-->
<group delimiter=",">
<text macro="author-short-zh" />
<text macro="issued-year-zh" />
<text macro="citation-locator-zh" />
</group>
</if>
<else>
<!--
Normal comma as a deliminater for references in the default language (English)
-->
<group delimiter=", ">
<text macro="author-short" />
<text macro="issued-year" />
<text macro="citation-locator" />
</group>
</else>
</choose>
</layout>
</citation>
However, the variable/tag lang-zh in the .bib file seems to be ignored even when I add such filed as lang-zh = {yes}, variable = {lang-zh}, or language = {lang-zh} to the .bib file, as shown below.
#article{chen2012,
title = {基于电无级变速器的内燃机最优控制策略及整车能量管理},
author = {陈骁 and 黄声华 and 万山明 and 庞珽},
journal = {电工技术学报},
volume = {27},
number = {2},
pages = {133--138},
year = {2012},
lang-zh = {yes},
variable = {lang-zh},
language = {lang-zh}
}
Then how should I add a filed or variable to the .bib file that can be recognised by the csl?
(M)WE
Full .csl file (say mod_apa_zh_pulipuli.csl)
You can find the .csl file from https://github.com/jgm/citeproc/issues/120#issuecomment-1296207148
(Its original csl called apa_zh_pulipuli.csl is from https://raw.githubusercontent.com/pulipulichen/blogger/master/project/zotero/apa_zh_pulipuli.csl)
tests.bib
#book{xie2015,
title = {Dynamic Documents with {R} and knitr},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2015},
edition = {2nd},
note = {ISBN 978-1498716963},
url = {http://yihui.name/knitr/},
language = {English}
}
#article{chen2012,
title = {基于电无级变速器的内燃机最优控制策略及整车能量管理},
author = {陈骁 and 黄声华 and 万山明 and 庞珽},
journal = {电工技术学报},
volume = {27},
number = {2},
pages = {133--138},
year = {2012},
lang-zh = {yes},
variable = {lang-zh},
language = {lang-zh}
}
test.md
---
bibliography: [test.bib]
csl: mod_apa_zh_pulipuli.csl
---
#xie2015
#chen2012

As #adam.smith suggested here, using a CSL JSON (.json) file as a bibliography source does the trick:
Convert a .bib file to a CSL JSON (.json) file via pandoc by pandoc .\tests.bib -t csljson -o tests.json (see also an answer in TeX.SE);
Add "lang-zh": "yes" to the generated .json file (This process is mandatory since such a non-standard field as lang-zh = {yes} in .bib is not transferred to a CSL JSON);
Change the bibliography field in the YAML of .md file so that pandoc can refer to the .json file
MWE
test.json
[
{
"URL": "http://yihui.name/knitr/",
"author": [
{
"family": "Xie",
"given": "Yihui"
}
],
"edition": "2nd",
"id": "xie2015",
"issued": {
"date-parts": [
[
2015
]
]
},
"note": "ISBN 978-1498716963",
"publisher": "Chapman; Hall/CRC",
"publisher-place": "Boca Raton, Florida",
"title": "Dynamic Documents with R and knitr",
"type": "book"
},
{
"author": [
{
"family": "陈骁"
},
{
"family": "黄声华"
},
{
"family": "万山明"
},
{
"family": "庞珽"
}
],
"container-title": "电工技术学报",
"id": "chen2012",
"issue": "2",
"issued": {
"date-parts": [
[
2012
]
]
},
"page": "133-138",
"title": "基于电无级变速器的内燃机最优控制策略及整车能量管理",
"type": "article-journal",
"volume": "27",
"lang-zh": "yes"
}
]
test.md
---
bibliography: [test.bib]
csl: mod_apa_zh_pulipuli.csl
---
#xie2015
#chen2012

Related

How to display text coming from property with special character - adaptive cards

I am trying to create an adaptive card for an elastic alert. The payload I receive for the card kind of looks like the following json:
{
"hits": {
"max_score": null,
"hits": [
{
"fields": {
"log.#m":
"some log message"
,
"kubernetes.node.name": [
"node name"
],
"log.#l": [
"Error"
]
}
}
]
}
}
I, however, have some problems getting the fields into a TextBlock because of the dot notation or the .# in the fields names. If I remove them (only possible in the adaptive card designer with the sample data editor) I can display the data just fine. It is not possible to change the property names since this is an Elastic thing.
I tried a lot of possibilities for the text field.
through the UI editor
using [] brackets
using single quotes
combinations of the above...
{
"type": "Container",
"items": [
{
"$when": "${$index < 2}",
"type": "TextBlock",
"text": "${log.m}",
"$data": "${fields}"
}
],
"$data": "${$root.hits.hits}"
}
Does anyone have an idea how I could go about displaying the fields in a textblock?

Creating new project with template not renaming to sourceName

I've created a new Template for a .NET 6 project, and I'm trying to make sure it renames the project and solution file on creation. I have the following in my template.json file:
{
"$schema": "http://json.schemastore.org/template",
"author": "Jake Ford",
"classifications": [ "FordWareMVC", "FordWareMVC", "C#" ],
"identity": "FordWareTemplates.MVC",
"name": "FordWare MVC Template",
"shortName": "fordwaremvc",
"sourceName": "_fordwaremvc",
"tags": {
"language": "C#",
"type": "project"
}
}
and I am running the following command, using -n to set the source name and -o to set the folder directory for the new project:
dotnet new fordwaremvc -n NewProjectName -o NewProjectName
It creates the project, but the template/solution name is not "NewProjectName", it just uses the name of the original template project...
Am I doing something wrong with the sourceName?
Finally found the following:
sourceName: This is the value in your project/solution that will get replaced with the user-provided value in the -o parameter. Make sure this matches the name you chose when creating your template project / solution. The value above matches my project / solution name if you look at the template repo.
From here: https://knowyourtoolset.com/2021/08/creating-useful-net-templates/
The sourceName apparently needs to match the original solution/project name. I edited my template.json to this, and uninstalled/re-installed the template again and the original command worked:
{
"$schema": "http://json.schemastore.org/template",
"author": "Jake Ford",
"classifications": [ "FordWareMVC", "FordWareMVC", "C#" ],
"identity": "FordWareTemplates.MVC",
"name": "FordWare MVC Template",
"shortName": "fordwaremvc",
"sourceName": "FordWare_Template",
"tags": {
"language": "C#",
"type": "project"
}
}

Can't display images sourced from GraphQL, error [gatsby-plugin-image] missing image prop

I'm trying to source content with images from Contentful into Gatsby but I failed to get images displayed.
I installed gatsby-transformer-sharp, gatsby-plugin-image, gatsby-plugin-sharp, gatsby-remark-images and gatsby-remark-images-contentful.
down below is a simple of my code
import { GatsbyImage, getImage } from "gatsby-plugin-image"
const Projects = ({ data }) => {
const projects = data.projects.nodes
return (
<Layout>
<Seo
title={"Projects"}
description={"Projects & Websites I've Developed"}
/>
<div className={styles.portfolio}>
<h1>My Portfolio</h1>
<h2>Projects & Websites I've Developed</h2>
<div className={styles.projects}>
{projects.map(project => (
<Link
to={"/projects/" + project.slug}
key={project.id}
className={styles.project}
>
<GatsbyImage
image={getImage(project.thumb)}
alt={project.title}
/>
<div className={styles.cardText}>
<h3>{project.title}</h3>
<p>{project.stack}</p>
</div>
</Link>
))}
</div>
</div>
</Layout>
)
}
export default Projects
export const query = graphql`
query ProjectsPage {
projects: allContentfulProjects(sort: { fields: date, order: DESC }) {
nodes {
key
slug
stack
title
thumb {
gatsbyImageData(placeholder: BLURRED, layout: FULL_WIDTH)
}
id
}
}
}
`
here what i got from GraphQL
{
"data": {
"projects": {
"nodes": [
{
"key": "project",
"slug": "portfolio-website",
"stack": "html - css - javascript",
"title": "Portfolio Website",
"thumb": [
{
"gatsbyImageData": {
"images": {
"sources": [
{
"srcSet": "https://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=750&h=361&q=50&fm=webp 750w,\nhttps://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1080&h=520&q=50&fm=webp 1080w,\nhttps://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1366&h=658&q=50&fm=webp 1366w,\nhttps://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1920&h=925&q=50&fm=webp 1920w",
"sizes": "100vw",
"type": "image/webp"
}
],
"fallback": {
"src": "https://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1920&h=925&q=50&fm=png",
"srcSet": "https://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=750&h=361&q=50&fm=png 750w,\nhttps://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1080&h=520&q=50&fm=png 1080w,\nhttps://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1366&h=658&q=50&fm=png 1366w,\nhttps://images.ctfassets.net/kj59ethbquzj/1qDaw8RjPxxhzjOehxHz1g/152307656408e0efcf7c907a59cd91a7/personal-portfolio-website.png?w=1920&h=925&q=50&fm=png 1920w",
"sizes": "100vw"
}
},
"layout": "fullWidth",
"width": 1,
"height": 0.4817708333333333,
"placeholder": {
"fallback": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAMAAACDi47UAAABv1BMVEUaGhosLSN+gm9ORjIcHBwlJB8kJBgkJBclJBgeHRREORVFWEeEj5SNingqNys+x8tWzNFk1Nhq1dl42Nx51dp219xw19twxMhjyMxKys89x8wnZlw7MhUiIRtrKiRCLCBHys5bztJu1tuD2t501tp62N1519yokpF3b25My9A/yc4oZ10VFRUkJCQoKChHR0c1NTUqKSotOCxEw8dbxcllys1owcR30dR2z9Nyz9NkyM2+n52cjo0/wsc5vsMrXVNdTx2niSCnjCqniiOfgyAtOC1HsbVRq69errJcpah1y8982N1u1dpto7F7RlG7lpeLWXVFr7koYFYtKiJJQyxTTDZMRS9DPSssNytNk5VWf3VbfWVWdVlnsKxryc1ays+xJ06sCy2sCS2wCi2bJkYrXlUjIyMuLi48PDw0NDQsLCwrNyw6n6I/j5BJlZBJlJFavL5Xxco4v8XDEz+QCiSqCSuHCiCJDidhKS07OzszMzMeHRk4NSg7OCs5NSk5NSg6Nio5Nik7Nys6NyocGhI6OjkxMTEYGBgmJiUmJiYjJCQlJSUXFxcWFhYRERE0Lhw7NBxBORwpJRswMDA0NTUvbwraAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAB3RJTUUH5gUJBR4Qdhx/lQAAAGRJREFUCNeNzUEKglAAANEZ/5cgRLTO0ZWCTtS6jdfxEJ5BUNyF+FuIiNSit5zNiKuUAbBAMHLWqfQgctGJWsdqrze/9PH6Z+R3hNphe8z5HFIgQuFQqHbtHSVlyFN9n3w92DQfWKcTSK8wndgAAAAASUVORK5CYII="
what it might be wrong with My code? need some help :)
According to what you said in the comment section, I'd say that there's a position in projects that has no thumbnail defined (or not properly queried).
Try adding a condition wrapping the GatsbyImage display:
{project.thumb && <GatsbyImage
image={getImage(project.thumb)}
alt={project.title}
/>}
That said, check in which project you have no thumbnail.
Finally I have figured it out by
1- I removed all My content and images in Contentful CMS and create a fresh ones, It seemed there was a bug with sourcing Images into GraphQL where the Image src was always giving an empty array!!
2- Taking out getImage function and replace it with <GatsbyImage image={project.thumb.gatsbyImageData} alt={project.title}/>
,then gatsby clean to clear the .cashe and also triggered clean cashe and rebuild.
Now everything is works well.

Require file or image dynamically in require method

I am using reactnative for mobile application and got an issue
I have json file which i am requiring in js file.
In json file there is also lots of image path.
When I am requiring json file from a folder in my js file
then path will be changed for that images which is in json file,
and I am also not able to pass the dynamic string in require method.
Here is my code in JSON file:
{
"Industry": [
{
"Id": "1",
"UpperImg": "../../../uploads/bposervices/industry/Bankingimg.png",
"FiledName": "Financial Services",
"FileName": "FS.json",
"Url" :"uploads/json/FS.json"
},
{
"Id": "2",
"UpperImg": "../../../uploads/bposervices/industry/Insimg.png",
"FiledName": "Insurance",
"FileName": "Insurance.json",
"Url" :"uploads/json/Insurance.json"
}
],
"Enterprises": [
{
"Id": "1",
"UpperImg": "uploads/bposervices/enterprise/Faimg.png",
"FiledName": "Finance & Accounting",
"FileName": "FandA.json",
"Url" :"uploads/json/FandA.json"
},
{
"Id": "2",
"UpperImg": "uploads/bposervices/enterprise/Spimg.png",
"FiledName": "Sourcing & Procurement",
"FileName": "SandP.json",
"Url" :"uploads/json/SandP.json"
}
]
}
Here is my js file:
const abc = require('../../folder/a.json)
class B extends component {
render() {
return (
<Container style={styles.container}>
<Content>
<List
dataArray={abc.industry} renderRow={dataIndustry =>
<ListItem>
<Card>
<CardItem cardBody>
<Image source={dataIndustry.UpperImg}/>
// or <Image source ={require(dataIndustry.UpperImg)/>
</CardItem>
<CardItem>
<Text>{dataIndustry.FiledName}</Text>
</CardItem>
</Card>
</ListItem>
}
/>
</Content>
</Container>
);
}
}
when I iterate the the array of object of json file,
I get the image path which I pass in require method,
but it is not accepting dynamic image path in require
method neither in image source.
Can anyone suggest me how can I get the same?

React-Native: packager not detecting images

I can't figure out how to programmatically add in images in React-Native. I have a directory, /img, full of images, and a json file, data.json full of data entries that have corresponding and image file paths:
[
{
"id": "1",
"img": "img1.png"
},
{
"id": "2",
"img": "img2.png"
}
]
I have loaded data.json into a variable with var data = require('data.json'), and I can access the image paths normally through data[0].img. Also, I can create Image tags that display the images through <Image source={{uri = "./img/img1.png"}} style={styles.img}/>.
However, when I try to combine the two, with <Image source={{uri = "./img/" + data[0].img}} style={styles.img}/>, I get this error: Requiring unknown module "./img/img1.png". If you are sure the module is there, try restarting the packager.
I have restarted my simulator multiple times, searched here and the documentation for hours to figure out what I'm doing wrong. Any help would be greatly appreciated.
You cannot show local images this way.
What you can do is the following :
[
{
"id": "1",
"img": require("./img/img1.png")
},
{
"id": "2",
"img": require("./img/img2.png")
}
]
then <Image source={data[0].img} style={styles.img} />
You have two "errors" in your code: object key is not assigned with = but with :. And you can't combine strings in this case, since AFAIK, there's ultimately used require() for images and it doesn't accept anything other but plain strings.
I'd encourage you to do it like this:
const assets = {
img1: './img'+ data[0].img
}
...
<Image source={{uri: assets.img1} style={styles.img}/>

Resources