How to create a custom style in biblatex

biberbiblatexciting

I use texstudio with windows 11. I have to use ama style in the bibliography in my report. I already have the ama style here. What is missing is numeric citing and the numbers in citation must be superscript. I want to prepare bibliography like this with superscipt numeric citation. I cannot use ama.bst already available for bibtex, because I have to divide in bibliography like articles, websources. Please tell me how can I get superscript numeric citation. I have tried doing following by combining this and this, but gives error. I do not know coding except in matlab.

\documentclass[12pt,abstract = true,toc = flat,toc = bib]{scrreprt}
\usepackage[english]{babel}
\usepackage[hidelinks]{hyperref}
\usepackage{url}


\usepackage[backend=biber, style=authoryear, bibstyle=authortitle, maxcitenames=2, maxbibnames=99, isbn=false, natbib = true, firstinits=true, uniquename=false, uniquelist=false, terseinits,citestyle=numeric-comp,labeldateparts]{biblatex}
\addbibresource{example.bib}
\begin{filecontents}{example.bib}
    @article{baillie_deliver_2021,
        title = {A Long url},
        url = {https://www.hydrocarbonprocessing.com/magazine/2021/september-2021/catalysts/deliver-high-levels-of-sox-reduction-with-sox-reduction-additive},
        journal = {this url goes out of margin},
        author = {Test},
        month = march,
        year = {2022},
    },
    @article{responsetoukaraniancrisis,
        title = {BAPS Responds to Ukrainian Humanitarian Crisis, Poland},
        url = {https://www.baps.org/Photos/2022/Emergency-Response-in-Rzesz243w-Poland-24266.aspx?mid=226449},
        journal = {BAPS News UK and Europe},
        author = {BAPS},
        month = march,
        year = {2022}
    }
\DeclareNameAlias{sortname}{last-first}
\renewcommand*{\revsdnamepunct}{}
\newrobustcmd{\mkbibsubscript}[1]{%
    \unspace\allowhyphens\textsubscript{%
        \begingroup
        \protected\long\def\mkbibsuperscript##1{%
            \blx@warning{Nested superscript}%
            \mkbibbrackets{##1}}%
        #1\endgroup}}

\DeclareCiteCommand{\subcite}[\mkbibsubscript]
{\usebibmacro{cite:init}%
    \let\multicitedelim=\supercitedelim
    \iffieldundef{prenote}
    {}
    {\BibliographyWarning{Ignoring prenote argument}}%
    \iffieldundef{postnote}
    {}
    {\BibliographyWarning{Ignoring postnote argument}}}
{\usebibmacro{citeindex}%
    \usebibmacro{cite:comp}}
{}
{\usebibmacro{cite:dump}}
%
\makeatletter
\renewcommand\@biblabel[1]{#1.}
\makeatother

\DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{{#1\isdot}}
\renewbibmacro{in:}{}
\DeclareFieldFormat{pages}{#1}
\renewcommand*{\bibpagespunct}{\addcolon}

% Normal title font (remove italic)
\DeclareFieldFormat{journaltitle}{#1\addperiod}
\DeclareFieldFormat{booktitle}{{#1}}
\DeclareFieldFormat{title}{{#1}}

% Year after title
\renewbibmacro*{journal+issuetitle}{%
    \usebibmacro{journal}%
    \setunit*{\addspace}%
    \iffieldundef{series}
    {}
    {\newunit
        \printfield{series}%
        \setunit{\addspace}}%
    \usebibmacro{issue+date}%
    \setunit{\addsemicolon\addspace}%
    \usebibmacro{volume+number+eid}%
    \setunit{\addcolon\space}%
    \usebibmacro{issue}%
    \newunit%
}

\newrobustcmd{\mkbibsubscript}[1]{%
    \unspace\allowhyphens\textsubscript{%
        \begingroup
        \protected\long\def\mkbibsuperscript##1{%
            \blx@warning{Nested superscript}%
            \mkbibbrackets{##1}}%
        #1\endgroup}}

\DeclareCiteCommand{\subcite}[\mkbibsubscript]
{\usebibmacro{cite:init}%
    \let\multicitedelim=\supercitedelim
    \iffieldundef{prenote}
    {}
    {\BibliographyWarning{Ignoring prenote argument}}%
    \iffieldundef{postnote}
    {}
    {\BibliographyWarning{Ignoring postnote argument}}}
{\usebibmacro{citeindex}%
    \usebibmacro{cite:comp}}
{}
{\usebibmacro{cite:dump}}


% Print only the year
\renewbibmacro*{issue+date}{%
    \printfield{year}%
}

% Remove "and" from list of authors
\renewcommand*{\finalnamedelim}{\multinamedelim}    
\end{filecontents}
\begin{document}
    \supercite{responsetoukaraniancrisis}
    \nocite{*}
    \printbibliography
\end{document}

I need the following:
Please remove the word URL, In: from all things like websources, books…etc. The title of Journal or website must be in italic, but there must be period and space between the journal title and the year. How can i prevent url from starting into current line and put it to next line if it is too long that it goes into margin.

We are able to make custom style i.e.,bst files in bibtex easily by answering questions in latex makebst. Is there any similar way to create custom style in biblatex?

Best Answer

Here is a stab at a numeric AMA style with biblatex. Note that if you want to submit your paper to a journal it is unlikely that you can use biblatex. Most journals use the classical BibTeX-based approach. Journals that accept LaTeX submissions often have templates or at least author guides on how to prepare a manuscript. biblatex is probably only supported if it is explicitly recommended there.

I did not address the URL breaking here, as that is discussed elsewhere, e.g. Line breaks of long URLs in biblatex bibliography?, How to break a long URL and more generally also in How to adjust the breaking in the bibliography?.

\documentclass[12pt,abstract = true,toc = flat,toc = bib]{scrreprt}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[
  backend=biber,
  natbib = true,
  style=ext-numeric-comp,
  sorting=none,
  minbibnames=3, maxbibnames=6,
  uniquename=false, uniquelist=false,
  giveninits=true, terseinits,
  articlein=false, innamebeforetitle=true,
  isbn=false,
  urldate=long, dateabbrev=false,
  autocite=superscript,
]{biblatex}
\usepackage[hidelinks]{hyperref}

\DeclareNameAlias{sortname}{family-given}

\DeclareNameAlias{author}{sortname}
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias{translator}{sortname}

\renewcommand*{\revsdnamepunct}{}
\DeclareDelimAlias{finalnamedelim}{multinamedelim}

\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {title}{#1}

\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit*{\addspace}%
  \iffieldundef{series}
    {}
    {\newunit
     \printfield{series}%
     \setunit{\addspace}}%
  \usebibmacro{issue+date}%
  \setunit{\addsemicolon\addspace}%
  \usebibmacro{volume+number+eid}%
  \setunit{\addcolon\space}%
  \usebibmacro{issue}}

\DeclareFieldFormat[article,periodical]{number}{\mkbibparens{#1}}
\renewcommand*{\volnumdelim}{}

\renewbibmacro*{issue+date}{%
  \usebibmacro{date}}

\renewbibmacro*{pubinstorg+location+date}[1]{%
  \printlist{location}%
  \iflistundef{#1}
    {\setunit*{\addsemicolon\space}}
    {\setunit*{\addcolon\space}}%
  \printlist{#1}%
  \setunit*{\addsemicolon\space}%
  \usebibmacro{date}%
  \newunit}

\renewcommand*{\bibpagespunct}{\addcolon}
\DeclareFieldFormat{pages}{#1}

\DeclareFieldFormat{doi}{%
  doi\addcolon\space
  \ifhyperref
    {\href{https://doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}

\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space#1}
\newbibmacro*{url+urldate}{%
  \usebibmacro{url}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addperiod\space}%
     \usebibmacro{urldate}}}

\DefineBibliographyStrings{english}{
  urlseen = {accessed},
}


\begin{filecontents}[force]{\jobname.bib}
@article{baillie_deliver_2021,
  title   = {A Long url},
  url     = {https://www.hydrocarbonprocessing.com/magazine/2021/september-2021/catalysts/deliver-high-levels-of-sox-reduction-with-sox-reduction-additive},
  urldate = {2022-03-12},
  journal = {this url goes out of margin},
  author  = {Test},
  year    = {2022},
}
@article{responsetoukaraniancrisis,
  title   = {BAPS Responds to Ukrainian Humanitarian Crisis, Poland},
  url     = {https://www.baps.org/Photos/2022/Emergency-Response-in-Rzesz243w-Poland-24266.aspx?mid=226449},
  journal = {BAPS News UK and Europe},
  author  = {BAPS},
  year    = {2022},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
  \autocite{responsetoukaraniancrisis,baillie_deliver_2021,
    sigfridsson,worman,nussbaum,companion,westfahl:space}
  \printbibliography
\end{document}

Sigfridsson E, Ryde U. Comparison of methods for deriving atomic charges from the electrostatic potential and moments. Journal of Computational Chemistry 1998; 19(4):377–395. doi: 10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P.