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

Set html element's attribute lang according to document's language #26

Merged
merged 2 commits into from
Jul 7, 2020

Conversation

cspiel
Copy link
Contributor

@cspiel cspiel commented Jul 3, 2020

This P/R addresses issue #25. Its primary
target is to provide transparent setting of the
lang attribute for the whole HTML document
based on the LaTeX

  • document options,
  • language packages, or
  • babel's
    • package options or
    • \selectlanguage (in the preamble)

It has turned out that the central function, a
map from babel language names
(e.g. swissgerman) to language codes
(e.g. de-CH) is also suitable to implement
some of the missing babel environments and
macros e.g. \foreignlanguage{LANG}{TEXT}.
Their implementation is trivial. The
documentation has been extended and updated
accordingly.

Known Problem: Babel allows for a quirky way
to set the document's main language

\usepackage[main=italian,french]{babel}

which makes italian the main language. This
P/R partially implements parsing the main
modifier, but ''babel.hva'' ignores it (due to
standard parsing of the package's options) and
thus the document's main language is wrongly
detected when main= is used.

@maranget
Copy link
Owner

maranget commented Jul 6, 2020

Hi, I am a bit concerned about default behaviour. At the moment if no language is specified, the PR emits a lang="en" attribute to the <html .. > element. Wouln't the previous behaviour of not emitting any lang attribute be more logical ?

I'd also like to have a look at the main=... question, as I do not understand exactly why babel.hva cannot parse the main=italian optional package argument.

  More precisely, while parsing the options of package pkg,
  if an option 'key' is not declared (by \DeclareOption
  from package.hva), then option @defopt is called with
  argument 'key'.

  See the handling of 'main=<lang>' by babel.hva for an example.
@maranget
Copy link
Owner

maranget commented Jul 6, 2020

I'd also like to have a look at the main=... question, as I do not understand exactly why babel.hva cannot parse the main=italian optional package argument.

My commit to your PR attempts precisely to do this. I had to modify package.hva a bit. Would you please have a look on it ?

Copy link
Contributor Author

@cspiel cspiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good and passed all my tests.
Now main= works as expected.

@maranget
Copy link
Owner

maranget commented Jul 6, 2020

Code looks good and passed all my tests.
Now main= works as expected.

I am glad it does. What about my other comment on not having a lang attribute when no language is specified?

@cspiel
Copy link
Contributor Author

cspiel commented Jul 6, 2020

I know you are afraid of breaking backward compatibility with
the introduction of lang="en" as default.

  1. A document that does not mention any language, e.g. via babel
    is treated as (US-)English by LaTeX/TeX -- in particular when it comes
    to hyphenation. So, it is transparent to the user that her Hevea-translated
    HTML-version of the document gets lang="en". The document's language
    should be a document property and not a (configurable?!) browser
    property.
  2. W3 kind of cheers for this attribute, but it really plays out with
    translation/interoperability and there with screen readers.

So, I'm inclined to have a default lang-attribute, though I'm not sure which
to prefer: en or en-US.

@maranget
Copy link
Owner

maranget commented Jul 7, 2020

Hi,

Ok I see. Although I'd rather had have language unspecified for pages in English, that pages in French with lang="en" specification, I'll follow your suggestion and merge the PR.

Thanks a lot for your contribution.

@maranget maranget merged commit 481903f into maranget:master Jul 7, 2020
@maranget maranget mentioned this pull request Jul 7, 2020
@cspiel cspiel deleted the lang-attribute branch July 7, 2020 08:40
maranget added a commit that referenced this pull request Oct 19, 2020
#26)

* Set `html` element's attribute `lang` according to the LaTeX document's language.

* Enhance \usepakage optional argument.

  More precisely, while parsing the options of package pkg,
  if an option 'key' is not declared (by \DeclareOption
  from package.hva), then option @defopt is called with
  argument 'key'.

  See the handling of 'main=<lang>' by babel.hva for an example.

Co-authored-by: Luc Maranget <Luc.Maranget@inria.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants