summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-10-30 19:39:44 +0000
committerKarl Berry <karl@freefriends.org>2021-10-30 19:39:44 +0000
commitf7b4a9a5747d771354b32ab1e1ba9e2dfd405982 (patch)
tree7e8d68cba5e0ee0734bc97994de93add1c0c2e26
parentb4b019077d0533f1cb161ba8f6090cc4c116d3ed (diff)
ccref (30oct21)
git-svn-id: svn://tug.org/texlive/trunk@60900 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/ccref/README.md23
-rw-r--r--Master/texmf-dist/doc/latex/ccref/ccref-doc.pdfbin95346 -> 99921 bytes
-rw-r--r--Master/texmf-dist/doc/latex/ccref/ccref-doc.tex70
-rw-r--r--Master/texmf-dist/tex/latex/ccref/ccref.sty212
4 files changed, 162 insertions, 143 deletions
diff --git a/Master/texmf-dist/doc/latex/ccref/README.md b/Master/texmf-dist/doc/latex/ccref/README.md
index 513140e90c2..c2f084b5183 100644
--- a/Master/texmf-dist/doc/latex/ccref/README.md
+++ b/Master/texmf-dist/doc/latex/ccref/README.md
@@ -1,6 +1,6 @@
<!-- Copyright (C) 2021 by Jinwen XU -->
-# ccref - cleveref with proper definite articles
+# ccref - cross referencing with proper definite articles
"ccref" is a LaTeX package aimed at helping `\cref` addressing the definite articles properly (especially for the article contractions in many European languages).
@@ -10,14 +10,14 @@ By default, when using cleveref's `\cref` to reference theorem-like environments
As an example, if we define the French names to be:
```latex
-\crefname{theorem}{le théorème}{les théorème}
+\crefname{theorem}{le théorème}{les théorèmes}
\crefname{proposition}{la proposition}{les propositions}
```
-Then when one writes
+Then when one writes (which means "*We can deduce this from ...*"):
```latex
On peut le déduire de \cref{thm1,thm2,prop3}.
```
-(which means "*We can deduce this from ...*") the result would be
+the result would be:
> On peut le déduire **de les** théorèmes 1 et 2 et **la** proposition 3.
which is wrong, as the correct result should be:
@@ -29,10 +29,9 @@ which is wrong, as the correct result should be:
Thus, it would be better to have a new command `\ccref[<prep>]{<labels>}`, and to use it like
```
-\ccref*[de]{thm1,thm2,prop3}
+\ccref[de]{thm1,thm2,prop3}
```
in order to get "*des théorèmes 1 et 2 et de la proposition 3*".
-> The asterisk `*` here indicates that the preposition "de" will act on every definite article.
# Usage
@@ -43,14 +42,16 @@ Just load the package with
> "ccref" uses "cleveref" internally, thus it should usually be placed at the last of your preamble.
And then you can use the command `\ccref` as follows:
- - `\ccref[<prep>]{<labels>}`
- - This will pass the `<prep>` to the first definite article.
- - `\ccref*[<prep>]{<labels>}`
- - This will pass the `<prep>` to every definite article.
+- `\ccref[<prep>]{<labels>}`
+ - This will pass the preposition `<prep>` to the definite articles that follows. Its behavior depends on the current language (for example, in Spanish, `<prep>` is passed only to the first definite article, while in French it is passed to everyone).
+- `\ccref-[<prep>]{<labels>}` and `\ccref+[<prep>]{<labels>}`
+ - In case the automatic version does not meet your needs, here are two manual ones. The `-` version passes the preposition `<prep>` only to the first definite article, while the `+` version passes `<prep>` to every definite article.
+
+> There is also a stared version `\ccref*` for generating the same text but without hyperlinks.
However, before using it, you should first define the `\crefname`s carefully. The definite article in `\crefname`s needs to be marked manually using `\ccmarkart`, for example:
```latex
-\crefname{theorem}{\ccmarkart{le} théorème}{\ccmarkart{les} théorème}
+\crefname{theorem}{\ccmarkart{le} théorème}{\ccmarkart{les} théorèmes}
```
diff --git a/Master/texmf-dist/doc/latex/ccref/ccref-doc.pdf b/Master/texmf-dist/doc/latex/ccref/ccref-doc.pdf
index 85d435a9f64..24a8277d3b5 100644
--- a/Master/texmf-dist/doc/latex/ccref/ccref-doc.pdf
+++ b/Master/texmf-dist/doc/latex/ccref/ccref-doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/ccref/ccref-doc.tex b/Master/texmf-dist/doc/latex/ccref/ccref-doc.tex
index 992ff0f181f..368a4896ac8 100644
--- a/Master/texmf-dist/doc/latex/ccref/ccref-doc.tex
+++ b/Master/texmf-dist/doc/latex/ccref/ccref-doc.tex
@@ -32,6 +32,7 @@
{
cref,crefname,
ccref,ccmarkart,
+ selectlanguage,
}
}
\lstnewenvironment{code}%
@@ -67,49 +68,52 @@
title={\scshape\sffamily #1}]%
}{\end{tcolorbox}\ResumeLineNumbers}
+%%================================
+%% demo
+%%================================
\newenvironment{demo}{%
\LocallyStopLineNumbers%
\begin{tcolorbox}[enhanced jigsaw,pad at break*=1mm,breakable,
- left=4mm,right=4mm,top=1mm,bottom=1mm,
+ left=4mm,right=4mm,top=0.5mm,bottom=0mm,
colback=gray!5!paper,boxrule=0pt,frame hidden,
borderline west={1.5mm}{0mm}{gray!55!paper},arc=.7mm]%
}{\end{tcolorbox}\ResumeLineNumbers}
-
\newcommand{\ccrefpackage}{\textsf{ccref}}
\begin{document}
-\title{\ccrefpackage{} - cleveref with proper definite articles}
+\title{\ccrefpackage{} - cross referencing with proper definite articles}
\author{Jinwen XU}
+\thanks{Corresponding to: \texttt{\ccrefpackage{} 2021/10/30}}
\date{October 2021, in Paris}
\maketitle
\begin{abstract}
\raggedleft
- The package \ccrefpackage{} is aimed at helping \lstinline|\cref| addressing the definite articles properly (especially for the article contractions in many European languages).
+ The package \ccrefpackage{} provides a command \lstinline|\ccref| parallel to \textsf{cleveref}'s \lstinline|\cref| for handling definite articles properly (especially for the article contractions in some European languages).
\end{abstract}
\section{The motivation}
-By default, when using \textsf{cleveref}'s \lstinline|\cref| to reference theorem-like environments, the names do not contain definite articles. This may be acceptable for English, but certainly not good enough for languages such as French, Italian, Portuguese, Spanish, etc. -- in these cases there shall be grammatical errors and would give you a strong feeling that it is machine-generated.
+By default, with \textsf{cleveref}'s \lstinline|\cref| to reference theorem-like environments, the names do not contain definite articles. While this might be acceptable for English, it is certainly not good enough for languages such as French, Italian, Portuguese, Spanish, etc. -- in these cases there shall be grammatical errors and would give you a strong feeling that it is machine-generated.
-As an example, if we define the French names to be:
+However, even if we manually add the definite articles to the names, there would still be other problems. As an example, if we define the French names to be:
\begin{code}
-\crefname{theorem}{le théorème}{les théorème}
+\crefname{theorem}{le théorème}{les théorèmes}
\crefname{proposition}{la proposition}{les propositions}
\end{code}
-then when one writes (which means ``\emph{We can deduce this from ...}'' in French)
+then when one writes (which means ``\emph{We can deduce this from ...}'')
\begin{code}
On peut le déduire de \cref{thm1,thm2,prop3}.
\end{code}
-the result would be
+the result would be:
\begin{demo}
On peut le déduire \textbf{de les} théorèmes 1 et 2 et \textbf{la} proposition 3.
@@ -121,23 +125,23 @@ which is wrong, as the correct result should be:
On peut le déduire \textbf{des} théorèmes 1 et 2 et \textbf{de la} proposition 3.
\end{demo}
-\lstinline|\cref| cannot handle such cases correctly --- and that is when \lstinline|\ccref| comes into play.
+\lstinline|\cref| cannot handle such cases automatically --- and that is when \lstinline|\ccref| comes into play.
\section{The usage}
\subsection[How to load it]{How to load it\,?}
-Simply load the package with
+Simply load the package with:
\begin{code}
\usepackage{ccref}
\end{code}
\begin{tip}
- \begin{itemize}\small
- \item \ccrefpackage{} uses \textsf{cleveref} internally, thus it should usually be placed at the last of your preamble.
- \item To handle article contractions correctly, \lstinline|\ccref| shall detect the current language, thus you need to use packages such as \textsf{babel} or \textsf{polyglossia} to set your languages appropriately.
+ \begin{itemize}
+ \item Since \ccrefpackage{} uses \textsf{cleveref} internally, it should usually be placed at the last of your preamble, and notably, after \textsf{varioref} and \textsf{hyperref}.
+ \item To handle article contractions correctly, \lstinline|\ccref| shall detect the current language, thus you need to use packages such as \textsf{babel} or \textsf{polyglossia} to set your languages, and use commands like \lstinline|\selectlanguage| to select them appropriately.
\end{itemize}
\end{tip}
@@ -147,18 +151,22 @@ Then you can use the command \lstinline|\ccref| as follows:
\begin{itemize}
\item \lstinline|\ccref[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}|
\begin{itemize}
- \item This will pass the preposition \meta{prep} to the first definite article.
+ \item This will pass the preposition \meta{prep} to the definite articles that follows. Its behavior depends on the current language (for example, in Spanish, \meta{prep} is passed only to the first definite article, while in French it is passed to everyone).
\end{itemize}
- \item \lstinline|\ccref*[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}|
+ \item \lstinline|\ccref-[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}| and \lstinline|\ccref+[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}|
\begin{itemize}
- \item This will pass the preposition \meta{prep} to every definite article.
+ \item In case the automatic version does not meet your needs, here are two manual ones. The \verb|-| version passes the preposition \meta{prep} only to the first definite article, while the \verb|+| version passes \meta{prep} to every definite article.
\end{itemize}
\end{itemize}
+\begin{tip}
+ There is also a stared version \lstinline|\ccref*| for generating the same referencing text but without creating hyperlinks.
+\end{tip}
+
However, before using it, you should first define the \lstinline|\crefname|s carefully. The definite article in \lstinline|\crefname|s needs to be marked manually using \lstinline|\ccmarkart|, for example:
\begin{code}
-\crefname{theorem}{\ccmarkart{le} théorème}{\ccmarkart{les} théorème}
+\crefname{theorem}{\ccmarkart{le} théorème}{\ccmarkart{les} théorèmes}
\end{code}
@@ -168,41 +176,31 @@ Let us come back to the example at the beginning, now you can do this:
\begin{code}
\crefname{theorem}{\ccmarkart{le} théorème}
- {\ccmarkart{les} théorème}
-\crefname{proposition}{\ccmarkart{le} proposition}
+ {\ccmarkart{les} théorèmes}
+\crefname{proposition}{\ccmarkart{la} proposition}
{\ccmarkart{les} propositions}
\end{code}
-And the sentence shall be written as\footnote{Here the stared version is used because we want the preposition ``de'' to be passed to every definite article.}:
+And the sentence shall be written as:
\begin{code}
-On peut le déduire \ccref*[de]{thm1,thm2,prop3}.
+On peut le déduire \ccref[de]{thm1,thm2,prop3}.
\end{code}
-which would result in:
+which would result in (provided that you have done \lstinline|\selectlanguage{french}|):
\begin{demo}
On peut le déduire \textbf{des} théorèmes 1 et 2 et \textbf{de la} proposition 3.
\end{demo}
-As another example, with
-
-\begin{code}
-Pensez \ccref*[à]{thm1,thm2,prop3}.
-\end{code}
-
-one would get something like:
-
-\begin{demo}
- Pensez \textbf{aux} théorèmes 1 et 2 et \textbf{à la} proposition 3.
-\end{demo}
-
+Voilà !
\section{Known issues}
\begin{itemize}
\item \ccrefpackage{} currently only works for French, Italian, Portuguese (both European and Brazilian) and Spanish, certainly more would be added to this list.
- \item In the case that the initial letter of \meta{prep} is capitalized, \ccrefpackage{} cannot yet handle the case changes automatically. However, this should be a rare occurrence.
+ \item The current mechanism does not work for German. However, the author has planed to adopt a more refined approach in later versions in order to support the various situations in German.
+ \item In case that the initial letter of \meta{prep} is capitalized, \ccrefpackage{} cannot yet handle the case changes automatically. However, this should be a rare occurrence.
\item The names of theorem-like environments are not provided --- for the moment you need to define them all by yourself. However, users are encouraged to use the \ProjLib{} toolkit, which already handles everything for you.
\end{itemize}
diff --git a/Master/texmf-dist/tex/latex/ccref/ccref.sty b/Master/texmf-dist/tex/latex/ccref/ccref.sty
index a507a2652cf..4358237afa4 100644
--- a/Master/texmf-dist/tex/latex/ccref/ccref.sty
+++ b/Master/texmf-dist/tex/latex/ccref/ccref.sty
@@ -12,21 +12,28 @@
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
\ProvidesExplPackage
{ccref}
- {2021/10/29}
+ {2021/10/30}
{}
- {cleveref with article contraction}
+ {Cross referencing with proper definite articles}
\RequirePackage{cleveref}
\tl_gset:Nn \g_ccref_prepf_tl {}
\tl_gset:Nn \g_ccref_prep_tl {}
-\NewDocumentCommand{\ccref}{sO{}m}{
- \IfBooleanTF{ #1 }{
- \tl_gset:Nn \g_ccref_prep_tl { #2 }
+\NewDocumentCommand{\ccref}{st-t+O{}m}{
+ \IfBooleanTF{ #2 }{
+ \tl_gset:Nn \g_ccref_prepf_tl { #4 }
}{
- \tl_gset:Nn \g_ccref_prepf_tl { #2 }
+ \IfBooleanTF{ #3 }{
+ \tl_gset:Nn \g_ccref_prep_tl { #4 }
+ }{
+ \str_case_e:nn { \ccref_prep_mode:nn } {
+ { - } { \tl_gset:Nn \g_ccref_prepf_tl { #4 } }
+ { + } { \tl_gset:Nn \g_ccref_prep_tl { #4 } }
+ }
+ }
}
- \cref {#3}
+ \IfBooleanTF{ #1 } { \cref*{#5} } { \cref{#5} }
\tl_gset:Nn \g_ccref_prep_tl {}
}
@@ -37,97 +44,110 @@
\tl_gset:Nn \g_ccref_prepf_tl {}
}
-\cs_set:Npn \ccref_contraction:nn #1#2 {
+\cs_set:Npn \ccref_prep_mode:nn {
\str_case_e:nn { \languagename }
{
- {french}{
- \str_case_e:nnF {#1~#2} {
- {à~le} {au}
- {à~la} {à~la}
- {à~l'} {à~l'}
- {à~les} {aux}
- {de~le} {du}
- {de~la} {de~la}
- {de~l'} {de~l'}
- {de~les} {des}
- }{#2}
- }
- {italian}{
- \str_case_e:nnF {#1~#2} {
- {a~il} {al}
- {a~lo} {allo}
- {a~l'} {all'}
- {a~la} {alla}
- {di~il} {del}
- {di~lo} {dello}
- {di~l'} {dell'}
- {di~la} {della}
- {da~il} {dal}
- {da~lo} {dallo}
- {da~l'} {dall'}
- {da~la} {dalla}
- {in~il} {nel}
- {in~lo} {nello}
- {in~l'} {nell'}
- {in~la} {nella}
- {su~il} {sul}
- {su~lo} {sullo}
- {su~l'} {sull'}
- {su~la} {sulla}
- {a~i} {ai}
- {a~gli} {agli}
- {a~le} {alle}
- {di~i} {dei}
- {di~gli} {degli}
- {di~le} {delle}
- {da~i} {dai}
- {da~gli} {dagli}
- {da~le} {dalle}
- {in~i} {nei}
- {in~gli} {negli}
- {in~le} {nelle}
- {su~i} {sui}
- {su~gli} {sugli}
- {su~le} {sulle}
- }{#2}
- }
- {portuguese}{
- \str_case_e:nnF {#1~#2} {
- {a~o} {ao}
- {a~a} {à}
- {a~os} {aos}
- {a~as} {às}
- {de~o} {do}
- {de~a} {da}
- {de~os} {dos}
- {de~as} {das}
- {em~o} {no}
- {em~a} {na}
- {em~os} {nos}
- {em~as} {nas}
- }{#2}
- }
- {brazilian}{
- \str_case_e:nnF {#1~#2} {
- {a~o} {ao}
- {a~a} {à}
- {a~os} {aos}
- {a~as} {às}
- {de~o} {do}
- {de~a} {da}
- {de~os} {dos}
- {de~as} {das}
- {em~o} {no}
- {em~a} {na}
- {em~os} {nos}
- {em~as} {nas}
- }{#2}
- }
- {spanish}{
- \str_case_e:nnF {#1~#2} {
- {a~el} {al}
- {de~el} {del}
- }{#2}
+ {french} { + }
+ {italian} { + }
+ {spanish} { - }
+ {portuguese} { + }
+ {brazilian} { + }
+ }
+}
+
+\cs_set:Npn \ccref_contraction:nn #1#2 {
+ \str_if_eq:eeTF {#1} {} {#2} {
+ \str_case_e:nn { \languagename }
+ {
+ {french}{
+ \str_case_e:nnF {#1~#2} {
+ {à~le} {au}
+ {à~la} {à~la}
+ {à~l'} {à~l'}
+ {à~les} {aux}
+ {de~le} {du}
+ {de~la} {de~la}
+ {de~l'} {de~l'}
+ {de~les} {des}
+ }{#1~#2}
+ }
+ {italian}{
+ \str_case_e:nnF {#1~#2} {
+ {a~il} {al}
+ {a~lo} {allo}
+ {a~l'} {all'}
+ {a~la} {alla}
+ {di~il} {del}
+ {di~lo} {dello}
+ {di~l'} {dell'}
+ {di~la} {della}
+ {da~il} {dal}
+ {da~lo} {dallo}
+ {da~l'} {dall'}
+ {da~la} {dalla}
+ {in~il} {nel}
+ {in~lo} {nello}
+ {in~l'} {nell'}
+ {in~la} {nella}
+ {su~il} {sul}
+ {su~lo} {sullo}
+ {su~l'} {sull'}
+ {su~la} {sulla}
+ {a~i} {ai}
+ {a~gli} {agli}
+ {a~le} {alle}
+ {di~i} {dei}
+ {di~gli} {degli}
+ {di~le} {delle}
+ {da~i} {dai}
+ {da~gli} {dagli}
+ {da~le} {dalle}
+ {in~i} {nei}
+ {in~gli} {negli}
+ {in~le} {nelle}
+ {su~i} {sui}
+ {su~gli} {sugli}
+ {su~le} {sulle}
+ }{#1~#2}
+ }
+ {portuguese}{
+ \str_case_e:nnF {#1~#2} {
+ {a~o} {ao}
+ {a~a} {à}
+ {a~os} {aos}
+ {a~as} {às}
+ {de~o} {do}
+ {de~a} {da}
+ {de~os} {dos}
+ {de~as} {das}
+ {em~o} {no}
+ {em~a} {na}
+ {em~os} {nos}
+ {em~as} {nas}
+ }{#1~#2}
+ }
+ {brazilian}{
+ \str_case_e:nnF {#1~#2} {
+ {a~o} {ao}
+ {a~a} {à}
+ {a~os} {aos}
+ {a~as} {às}
+ {de~o} {do}
+ {de~a} {da}
+ {de~os} {dos}
+ {de~as} {das}
+ {em~o} {no}
+ {em~a} {na}
+ {em~os} {nos}
+ {em~as} {nas}
+ }{#1~#2}
+ }
+ {spanish}{
+ \str_case_e:nnF {#1~#2} {
+ {a~el} {al}
+ {de~el} {del}
+ }{#1~#2}
+ }
}
}
}