Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minus Operator not working #59

Open
smartens opened this issue Apr 18, 2020 · 9 comments
Open

Minus Operator not working #59

smartens opened this issue Apr 18, 2020 · 9 comments
Labels
defaults Related to default option values and renderer prototypes feature request latex Related to the LaTeX interface and implementation

Comments

@smartens
Copy link

smartens commented Apr 18, 2020

My problems with postnotes and prenotes was solved in issue #58.

I only got one problem left. The minus operator (-) is not working.

Input:

asdasdasd [@EswaranEtAl.1976].

asdasdasd [-@EswaranEtAl.1976].

asfasfs [@EswaranEtAl.1976, 2].

asfasfs [-@EswaranEtAl.1976, 2].

@EswaranEtAl.1976 asdf.

-@EswaranEtAl.1976 asdf.

@EswaranEtAl.1976 [22] asdf.

-@EswaranEtAl.1976 [22] asdf.

Output:

asdasdasd (Eswaran et al.1976).
asdasdasd (Eswaran et al.1976).
asfasfs (Eswaran et al.1976, S. 2).
asfasfs (Eswaran et al.1976, S. 2).
Eswaran et al.(1976) asdf.
Eswaran et al.(1976) asdf.
Eswaran et al.(1976, S. 22) asdf.
Eswaran et al.(1976, S. 22) asdf.

I created a MWE in overleaf https://www.overleaf.com/read/rhrgjhqyvhfp to demonstrate it.

@Witiko
Copy link
Owner

Witiko commented Apr 18, 2020

The minus operator currently has no effect on the LaTeX renderers. It is accepted by the parser to remain compatible with Pandoc, but Pandoc's behavior does not map well to the functionality provided by BibLaTeX, Natbib, and LaTeX, so it is ignored. What behavior would you expect?

@Witiko Witiko added latex Related to the LaTeX interface and implementation question labels Apr 18, 2020
@smartens
Copy link
Author

Actually I would expect something like this:

[-@EswaranEtAl.1976] (1976)

[-@EswaranEtAl.1976, 2] (1976, S. 2).

-@EswaranEtAl.1976 1976

+@EswaranEtAl.1976 Eswaran et al.

The last one is offtopic but I would like this kind of a behavior.

@Witiko
Copy link
Owner

Witiko commented Apr 18, 2020

Currently, the Markdown package has limited control over the formatting of citations. This is by design, so that the users can control the formatting of citations by changing the configuration of the citation backends.

For BibLaTeX and Natbib, a distinction is made between text citations (@doe92) and parenthesized citations ([@doe92]), since such support is directly provided by the backends (the \textcites and \autocites commands). No such support is provided for typesetting only the year (-@doe92 and [-@doe92]) in such a way that the year is guaranteed to uniquely identify a citation and consistency of formatting is guaranteed.

If you desire this functionality, I encourage you to redefine the corresponding citation renderers (cite and textCite) to use the BibLaTeX \citeyear command. However, you will need to do all the formatting (adding parentheses, prenotes, and postnotes) manually within the renderer to fit your citation format.

@smartens
Copy link
Author

But wouldn't that mean I lose the normal functionality if I understand you correctly?

I thought it is a feature. Because in your manual there is this example given:

Here is a simple parenthetical citation [@doe99] and here
is a string of several [see @doe99, pp. 33-35; also
@smith04, chap. 1].

A parenthetical citation can have a [prenote @doe99] and
a [@smith04 postnote]. The name of the author can be
suppressed by inserting a dash before the name of an
author as follows [-@smith04].

Here is a simple text citation @doe99 and here is
a string of several @doe99 [pp. 33-35; also @smith04,
chap. 1]. Here is one with the name of the author
suppressed -@doe99.

@Witiko
Copy link
Owner

Witiko commented Apr 19, 2020

But wouldn't that mean I lose the normal functionality if I understand you correctly?

You would need to hardcode the appearance of the citations in your renderer. For example, the \citeyear command is very plain and only prints a year, i.e. you would have to typeset the parentheses, prenotes, and postnotes yourself.

I thought it is a feature. Because in your manual there is this example given: [...]

This is only an example of the syntax, which is taken from Pandoc. The default LaTeX renderers ignore the minus sign, as explained above.

As a general rule, the default plain TeX / LaTeX / ConTeXt renderers are not required to be complete, and are expected to be redefined by the users if they require a specific rendering. We try to provide sane defaults where possible.

@smartens
Copy link
Author

smartens commented Apr 19, 2020

You would need to hardcode the appearance of the citations in your renderer. For example, the \citeyear command is very plain and only prints a year, i.e. you would have to typeset the parentheses, prenotes, and postnotes yourself.

As a general rule, the default plain TeX / LaTeX / ConTeXt renderers are not required to be complete, and are expected to be redefined by the users if they require a specific rendering. We try to provide sane defaults where possible.

Sure I understand. I already redefined the image renderer but I don't get my head around the logic to reimplement the cite and textcite renderer.

Source
The macro receives the parameter {⟨number of citations⟩} followed by {⟨prenote⟩}{⟨postnote⟩}{⟨name⟩} repeated ⟨number of citations⟩ times. The ⟨suppress author⟩ parameter is either the token -, when the author’s name is to be suppressed, or + otherwise.

How to know if a minus or plus is used? Because at other places the documentation says that the supress_author is a boolean value.

Define writer->citations as a function that will transform an input array of
citations cites to the output format. If text_cites is true, the citations should
be rendered in-text, when applicable. The cites array contains tables with the
following keys and values:
• suppress_author – If the value of the key is true, then the author of the work
should be omitted in the citation, when applicable.
• prenote – The value of the key is either nil or a rope that should be inserted
before the citation.
• postnote – The value of the key is either nil or a rope that should be inserted
after the citation.
• name – The value of this key is the citation name.

How do I get the values from this array?

This what I have now. I removed the checks from the default implementation. But I don't know how to check the value of suppress_author?

  cite = {
    \markdownLaTeXCitationsCounter=1%
    \def\markdownLaTeXCitationsTotal{#1}%
    \expandafter\expandafter\expandafter
    % How to know if author is surpressed or not ... or if there is minus or
    % plus token?
    \markdownLaTeXBibLaTeXCitations
    \expandafter{\expandafter}%
  },
  textCite = {%
    \markdownLaTeXCitationsCounter=1%
    \def\markdownLaTeXCitationsTotal{#1}%
    \expandafter\expandafter\expandafter
    \markdownLaTeXBibLaTeXTextCitations
    \expandafter{\expandafter}%
  }

I also created modified version of the citations macros ...

    % Suppress author in parenthesis
    \def\markdownLaTeXBibLaTeXCitationsSupressAuthor#1#2#3#4#5{%
    \advance\markdownLaTeXCitationsCounter by 1\relax
    \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax
    \citeyear#1[#3][#4]{#5}%
    \expandafter\@gobbletwo
    \fi\markdownLaTeXBibLaTeXCitationsSupressAuthor{#1[#3][#4]{#5}}}

    % Cite year in text
    \def\markdownLaTeXBibLaTeXTextCitationsCiteYear#1#2#3#4#5{%
    \advance\markdownLaTeXCitationsCounter by 1\relax
    \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax
    \citeyear#1[#3][#4]{#5}%
    \expandafter\@gobbletwo
    \fi\markdownLaTeXBibLaTeXTextCitationsCiteYear{#1[#3][#4]{#5}}}

    % Cite author in text
    \def\markdownLaTeXBibLaTeXTextCitationsCiteAuthor#1#2#3#4#5{%
    \advance\markdownLaTeXCitationsCounter by 1\relax
    \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax
    \citeauthor#1[#3][#4]{#5}%
    \expandafter\@gobbletwo
    \fi\markdownLaTeXBibLaTeXTextCitationsAuthor{#1[#3][#4]{#5}}}

How do I check in the renderer if a token (- or +) was used?

Unluckily my knowledge of latex is limited. Is this the right direction that I'm going?

I'm guessing it's the #2 parameter that I have to check.

@Witiko
Copy link
Owner

Witiko commented Apr 20, 2020

[…] but I don't get my head around the logic to reimplement the cite and textcite renderer.

Source
The macro receives the parameter {⟨number of citations⟩} followed by {⟨prenote⟩}{⟨postnote⟩}{⟨name⟩} repeated ⟨number of citations⟩ times. The ⟨suppress author⟩ parameter is either the token -, when the author’s name is to be suppressed, or + otherwise.

Sorry, a crucial information was missing from the user manual:

Screenshot_20200420_121650

This is because the conversion of the manual from markdown.dtx to HTML is somewhat hacky and the \meta{suppress author} macro was split across several lines, confusing the converter. 😔

How to know if a minus or plus is used? Because at other places the documentation says that the supress_author is a boolean value.

It is a boolean value inside the Lua Markdown reader. After export to plain TeX, the boolean value is represented as either - (true) or + (false).

I'm guessing it's the #2 parameter that I have to check.

That is correct.

@smartens
Copy link
Author

It is a boolean value inside the Lua Markdown reader. After export to plain TeX, the boolean value is represented as either - (true) or + (false).

Ok that is great info 🙂. But what happens if there is no - or +. How does it evaluate other characters in front of the citations? Does it evaluate to false when nothing is used?

@Witiko
Copy link
Owner

Witiko commented Apr 23, 2020

It is a boolean value inside the Lua Markdown reader. After export to plain TeX, the boolean value is represented as either - (true) or + (false).

Ok that is great info 🙂. But what happens if there is no - or +. How does it evaluate other characters in front of the citations? Does it evaluate to false when nothing is used?

The + character is not supported by the citation syntax extension. The + in argument #2 of the renderer only signifies that there was no - before the citation. Unspecified prenotes and postnotes are represented as empty strings.

You can play around with this using the Lua CLI interface:

$ kpsewhich -a markdown-cli.lua
/usr/local/texlive/2018/texmf-dist/scripts/markdown/markdown-cli.lua
/home/witiko/texmf/tex/latex/markdown/markdown-cli.lua

$ texlua ~/texmf/tex/latex/markdown/markdown-cli.lua citations=true <<< '-@doe92'
\input ./ff47cb1c5d2c5d9113914a50761a1eb3.md.tex\relax{}
$ cat ff47cb1c5d2c5d9113914a50761a1eb3.md.tex
\markdownRendererTextCite{1}-{}{}{doe92}\relax

$ texlua ~/texmf/tex/latex/markdown/markdown-cli.lua citations=true <<< '@doe92'
\input ./a728f93f02f0e2812786d05d511e036f.md.tex\relax{}
$ cat a728f93f02f0e2812786d05d511e036f.md.tex
\markdownRendererTextCite{1}+{}{}{doe92}\relax

$ texlua ~/texmf/tex/latex/markdown/markdown-cli.lua citations=true <<< '+@doe92'
\input ./3f73b9201b0b24e9b897dfd478f96790.md.tex\relax{}
$ cat 3f73b9201b0b24e9b897dfd478f96790.md.tex
+@doe92\relax

@Witiko Witiko added the defaults Related to default option values and renderer prototypes label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defaults Related to default option values and renderer prototypes feature request latex Related to the LaTeX interface and implementation
Projects
None yet
Development

No branches or pull requests

2 participants