]> hydra-www.ietfng.org Git - mcv-academic/commitdiff
Add support for list of dates
authoradin <adin@ic.unicamp.br>
Fri, 24 Aug 2018 18:12:57 +0000 (15:12 -0300)
committeradin <adin@ic.unicamp.br>
Fri, 24 Aug 2018 18:12:57 +0000 (15:12 -0300)
README.md
cv.bbx [changed mode: 0755->0644]
cv.dbx

index dd3b2f44169c4442dfa70ac3091f54e34f804fac..5a65180994dd09ff8cac4d8ffeb6319db642c2c5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
 # About
 
-This style an extension for the [`moderncv`](moderncv) package for creating academic (or closely related) CVs. It aims to provide an easy way to maintain the entries in your CV by using [`biblatex`](biblatex) custom drivers to typeset the CV in multiple languages with minimal changes to the main document.
+This style an extension for the [`moderncv`](moderncv) package for creating academic (or closely related) CVs.  It aims to provide an easy way to maintain the entries in your CV by using [`biblatex`](biblatex) custom drivers to typeset the CV in multiple languages with minimal changes to the main document.
 
-I designed this interface because I needed to maintain my CV in several languages, and it was difficult to keep track of the different changes in all the versions. This style aims to ease that problem. 
+I designed this interface because I needed to maintain my CV in several languages, and it was difficult to keep track of the different changes in all the versions.  This style aims to ease that problem. 
 
 The other problem I'm trying to solve with this style is to make the process of changing parts of the CV more manageable.
 
@@ -46,7 +46,7 @@ For a particular language, you can execute
 make en
 ```
 
-The same holds for styles too, or the combination of the two. Note that the languages and styles are defined within the `Makefile` and should be the same as the ones defined within the style.
+The same holds for styles too, or the combination of the two.  Note that the languages and styles are defined within the `Makefile` and should be the same as the ones defined within the style.
 
 ## Customizing your CV
 
@@ -105,29 +105,29 @@ For more details, read on.
 
 # Academic Style
 
-The main idea of this style is to hold academic CV, as they have several entries of related items. For example, you want to put all your publications, guided theses, talks, etc. Most of the time, you will want to sort them in a given order, or print some of them, or do some strange things.
+The main idea of this style is to hold academic CV, as they have several entries of related items.  For example, you want to put all your publications, guided theses, talks, etc.  Most of the time, you will want to sort them in a given order, or print some of them, or do some strange things.
 
-Moreover, you may want to have all those entries in different languages and you may need to have the same version in different languages. If that is your case, fear no more. This probably help you easing that task.
+Moreover, you may want to have all those entries in different languages and you may need to have the same version in different languages.  If that is your case, fear no more.  This probably help you easing that task.
 
-To use the package you need to load it in the preamble, and pass the `moderncv` style that you want to use using the `style` keyword. Optionally, you can define to use `details=true` or not (as a boolean variable).
+To use the package you need to load it in the preamble, and pass the `moderncv` style that you want to use using the `style` keyword.  Optionally, you can define to use `details=true` or not (as a boolean variable).
 
 ```tex
 \usepacakge[style=academic, details]{academic}
 ```
 
-by default, `details` it is set to `true`. The available styles are the ones defined within `moderncv`, plus `academic`, that is a minor variation on the `classic` style, and `friggeri` that is a total new style that defines its own header and body.
+by default, `details` it is set to `true`.  The available styles are the ones defined within `moderncv`, plus `academic`, that is a minor variation on the `classic` style, and `friggeri` that is a total new style that defines its own header and body.
 
 ## How the style works
 
-The whole style is build around the idea of printing similar items in a similar fashion. For that reason, I chose to create `biblatex` drivers to handle the common entries that appeared in academic CVs.
+The whole style is build around the idea of printing similar items in a similar fashion.  For that reason, I chose to create `biblatex` drivers to handle the common entries that appeared in academic CVs.
 
-The `cv.tex` (that is, the main file that you will compile) only holds the way you want to layout your document. While all the data is maintained in other files that must be `.bib`. It depends on your choice, but you can have the files in one file or spread around.
+The `cv.tex` (that is, the main file that you will compile) only holds the way you want to layout your document.  While all the data is maintained in other files that must be `.bib`.  It depends on your choice, but you can have the files in one file or spread around.
 
-Then, another goal was to have multi language support. For that reason, the style gives commands to define languages variations of your strings and entries, and allow you to compile the entire document in a given language without making further changes to the document.
+Then, another goal was to have multi language support.  For that reason, the style gives commands to define languages variations of your strings and entries, and allow you to compile the entire document in a given language without making further changes to the document.
 
 ## Entries
 
-In general, the entries follow the same logic of the `.bib` files. Thus you create them with the syntax
+In general, the entries follow the same logic of the `.bib` files.  Thus you create them with the syntax
 
 ```tex
 @entry {
@@ -142,63 +142,65 @@ where `entry` is the name of the respective item (see options below), and `field
 
 The style defines the following entries (or types of data)
 
-- **Study**. Refers to a course or study you did. For example, your Ph.D., master, among others. It supports the following fields
-  * `date`: a range of dates in which the study happened. For example: to print 
+- **Study**.  Refers to a course or study you did.  For example, your Ph.D., master, among others.  It supports the following fields
+  * `date`: a range of dates in which the study happened.  For example: to print 
       + a range of dates with their months `1990-01/1995-01`,
       + a range of defined years `1990/1995`,
       + a range of years that hasn't ended (it continues to the present) `1990/`, or
       + a single year `1990`
-  * `title`: the name of the study or degree obtained. This field is a string.
-  * `organization`: the place where you did the studies. This field is a string.
-  * `country`: where you did the studies. This field is a string.
+  * `title`: the name of the study or degree obtained.  This field is a string.
+  * `organization`: the place where you did the studies.  This field is a string.
+  * `country`: where you did the studies.  This field is a string.
   * `description`: extra information you want to give about your studies.
 
-- **Position**. Refers to work related entries. It supports the following fields
-  * `date`: a range of dates in which you work in that position. It follows the same pattern of `study`.
-  * `title`: the name of the position you had. This field is a string or a `bibstring`.
-  * `organization`: the place where you worked. This field is a string.
-  * `country`: where you did the work. This field is a string.
-  * `description`: extra information you want to give about your position. What you did or achieve in such position.
+- **Position**.  Refers to work related entries.  It supports the following fields
+  * `date`: a range of dates in which you work in that position.  It follows the same pattern of `study`.
+  * `title`: the name of the position you had.  This field is a string or a `bibstring`.
+  * `organization`: the place where you worked.  This field is a string.
+  * `country`: where you did the work.  This field is a string.
+  * `description`: extra information you want to give about your position.  What you did or achieve in such position.
   
-- **Project**. Refers to research or industry projects you won or performed. For example, it aims to hold grants, industry projects, or related items. It supports the following fields
-  * `role`: your role in the project. This field is a string or a `bibstring`.
-  * `title`: the name of the project. This field is a string.
+- **Project**.  Refers to research or industry projects you won or performed.  For example, it aims to hold grants, industry projects, or related items.  It supports the following fields
+  * `role`: your role in the project.  This field is a string or a `bibstring`.
+  * `title`: the name of the project.  This field is a string.
   * `number`: the identifier (or list of identifiers separated by `and`) for the project.
   * `funding`: the name of the funding agency or organization that was in charge.
-  * `period`: the duration of the project. It should be an integer or a float in years (as the word `year` or `years` will be appended automatically when printed).
-  * `year`: the starting year of the project. This field is an integer number representing the year.
-  * `month`: the starting month of the project. This field should be a month that `biblatex` can understand (that is, a number or a three letter month representation).
-
-- **Thesis**. Refers to the theses you guided. It supports the following fields
-  * `author`: the student (author) of the theses that you guided. This field is a string.
-  * `title`: the title of the thesis. This field is a string.
-  * `date`: the date of the thesis. This field is a date from `biblatex`.
-  * `organization`: the institution where the thesis was done. This field is a string.
-  * `level`: the academic level of the degree that was awarded with the thesis. It supports the following `bibstrings`
+  * `period`: the duration of the project.  It should be an integer or a float in years (as the word `year` or `years` will be appended automatically when printed).
+  * `year`: the starting year of the project.  This field is an integer number representing the year.
+  * `month`: the starting month of the project.  This field should be a month that `biblatex` can understand (that is, a number or a three letter month representation).
+
+- **Thesis**.  Refers to the theses you guided.  It supports the following fields
+  * `author`: the student (author) of the theses that you guided.  This field is a string.
+  * `title`: the title of the thesis.  This field is a string.
+  * `date`: the date of the thesis.  This field is a date from `biblatex`.
+  * `organization`: the institution where the thesis was done.  This field is a string.
+  * `level`: the academic level of the degree that was awarded with the thesis.  It supports the following `bibstrings`
      + `undergrad`
      + `master`
      + `doctor`
-  * `note`: a small note to place at the end in parenthesis. This field is a string.
+  * `note`: a small note to place at the end in parenthesis.  This field is a string.
   
-- **Course**. Refers to courses you taught. It supports the following fields
-  * `title`: the title of the course taught. This field is a string.
-  * `date`: the date of the course. It follows the same pattern of `study`.
-  * `organization`: the institution where the course was taught. This field is a string.
-  * `description`: general description of the course. This field is a string.
+- **Course**.  Refers to courses you taught.  It supports the following fields
+  * `title`: the title of the course taught.  This field is a string.
+  * `date`: the date of the course.  It follows the same pattern of `study`.
+  * `dates`: alternatively, the course may have a set of dates that can be specified with this field instead.  It is a list of date separated by the keyword `and` (like authors in the standard bibtex), and each date follows the same pattern of `study`.  If a `date` is defined, it will take precedence over `dates`.
+  * `organization`: the institution where the course was taught.  This field is a string.
+  * `description`: general description of the course.  This field is a string.
   
-- **CVMisc**. Refers to general things that can be placed in the CV. For example, memberships, or items that need a short description and dates. It supports the following fields
-  * `title`: a principal description of the entry. This field is a string.
-  * `date`: the date of the entry. It follows the same pattern of `study`.
-  * `description`: general description of the entry. This field is a string.
+- **CVMisc**.  Refers to general things that can be placed in the CV.  For example, memberships, or items that need a short description and dates.  It supports the following fields
+  * `title`: a principal description of the entry.  This field is a string.
+  * `date`: the date of the entry.  It follows the same pattern of `study`.
+  * `dates`: a list of dates of the entry.  It follows the same patter of `course`.
+  * `description`: general description of the entry.  This field is a string.
 
  
 ## Fields
 
-The fields in these entries follow the same logic as the entries in `biblatex` or `bibtex` files. There are, however, some custom behaviors implemented.
+The fields in these entries follow the same logic as the entries in `biblatex` or `bibtex` files.  There are, however, some custom behaviors implemented.
 
 ### Date fields
 
-The dates in the CV allow to hold ranges. For brevity, the style truncates the day of all the dates, and displays only the month and year.
+The dates in the CV allow to hold ranges.  For brevity, the style truncates the day of all the dates, and displays only the month and year.
 
 The ranges allow to print the following options
 + a range of dates with their months `1990-01/1995-01`,
@@ -208,18 +210,18 @@ The ranges allow to print the following options
 
 ### String fields
 
-Most of the string fields have the options to create localized versions of each field. The different drivers will chose the correct language entry according to the current language set in the document. If the language is not found it will default to the field name without a language.
+Most of the string fields have the options to create localized versions of each field.  The different drivers will chose the correct language entry according to the current language set in the document.  If the language is not found it will default to the field name without a language.
 
 For example, the field `title` can be defined as
 - `title`: default information to be used in case the current language version of the field is not found.
 - `title-en`: English version of the field.
 - `title-es`: Spanish version of the field.
 
-And so on. The fields use the short version of the languages. Those can be set when the languages are defined.
+And so on.  The fields use the short version of the languages.  Those can be set when the languages are defined.
 
 A good rule of thumb is to define the default name with the language you want the field to appear, and then extend the field to other languages.
 
-Another use to the default fields is when you have a field that will use the same name regardless of the set language. For example, a proper name that will be the same in all the languages. Instead of defining the same string several times, you just define it once.
+Another use to the default fields is when you have a field that will use the same name regardless of the set language.  For example, a proper name that will be the same in all the languages.  Instead of defining the same string several times, you just define it once.
 
 Instead of defining
 ```tex
@@ -232,13 +234,13 @@ create a simpler version that will be used as default
 organization = {Proper name},
 ```
 
-The data model is created automatically based on the installed languages, and it will localized the corresponding string fields. Note that it will use the defined languages in the style, and not the ones defined by the `babel` package alone. See the [localization](#localization) for more details.
+The data model is created automatically based on the installed languages, and it will localized the corresponding string fields.  Note that it will use the defined languages in the style, and not the ones defined by the `babel` package alone.  See the [localization](#localization) for more details.
 
 ### Defined `bibstrings`
 
 Some fields allow to use `bibstrings` instead of a given string.
 
-A `bibstring` is a previously defined keyword that will be translated into a defined string. This allows to create common definitions (and their translations) to be used easily in the entries.
+A `bibstring` is a previously defined keyword that will be translated into a defined string.  This allows to create common definitions (and their translations) to be used easily in the entries.
 
 The `bibstrings` for general use are
   * `undergrad`: Undergraduate
@@ -267,15 +269,15 @@ Note that all these have translations to the other languages as well (here are t
 
 ### Within the style
 
-Currently the style supports three languages: `english`, `spanish`, and `portuguese`. I'm planing on extending it to other languages when I have time (but contributions for the translations are welcomed).
+Currently the style supports three languages: `english`, `spanish`, and `portuguese`.  I'm planing on extending it to other languages when I have time (but contributions for the translations are welcomed).
 
-The languages are defined in `language-cv.lbx` where the `bibstrings` are localized. The languages declared automatically create the custom entries in the data model by declaring the supported languages through
+The languages are defined in `language-cv.lbx` where the `bibstrings` are localized.  The languages declared automatically create the custom entries in the data model by declaring the supported languages through
 
 ```tex
 \babelshortnames{en=english, es=spanish}
 ```
 
-That is, a list of pairs `<abreviation>=<languagename>`. These languages are not necessarily the same as the ones declared in the main document.
+That is, a list of pairs `<abreviation>=<languagename>`.  These languages are not necessarily the same as the ones declared in the main document.
 
 The robust solution is to use `setlanguages.sty` configuration file in which this macro is declared, and later this file is read within the `cv.bbx` style.
 
@@ -299,13 +301,13 @@ Then, it is as simple as using the defined macro in any place you want your stri
 
 ### Setting the language
 
-The language changing mechanism is provided by the [`babel`](babel) package. Thus, you first need to include that in your document with the languages you want support for
+The language changing mechanism is provided by the [`babel`](babel) package.  Thus, you first need to include that in your document with the languages you want support for
 
 ```tex
 \usepackage[english, spanish]{babel}
 ```
 
-Then you select the language (**within** the document body, that is after the `\begin{document}`) using `\selectlanguage{<language>}`. Moreover, the style provides a macro to select the language through interpreting the short names that we defined before. You can use it as `\selectshortlanguage{<shortname>}`.
+Then you select the language (**within** the document body, that is after the `\begin{document}`) using `\selectlanguage{<language>}`.  Moreover, the style provides a macro to select the language through interpreting the short names that we defined before.  You can use it as `\selectshortlanguage{<shortname>}`.
 
 For aiding with automatic building (for example through `make`) you can define a macro, lets call it `\defaultopts`, that is declared outside of the document, like
 
@@ -322,7 +324,7 @@ For aiding with automatic building (for example through `make`) you can define a
 
 ## Printing the entries
 
-The entries are printed using the `\printbibliography` macro provided by [`biblatex`](biblatex) package. The style provides some wrappers to this macro by establishing the default types for each entry with
+The entries are printed using the `\printbibliography` macro provided by [`biblatex`](biblatex) package.  The style provides some wrappers to this macro by establishing the default types for each entry with
 * `\printstudies`
 * `\printpositions`
 * `\printprojects`
diff --git a/cv.bbx b/cv.bbx
old mode 100755 (executable)
new mode 100644 (file)
index 70928d5..9d5ac1b
--- a/cv.bbx
+++ b/cv.bbx
@@ -8,6 +8,9 @@
 % Create short names for languages
 \RequirePackage{pgfkeys}
 
+% Manipulate the strings
+\RequirePackage{xstring}
+
 %-------------------------------------------------------------------------------
 % Language handlers
 %-------------------------------------------------------------------------------
 %-------------------------------------------------------------------------------
 % Drivers
 %-------------------------------------------------------------------------------
-
 \DeclareBibliographyDriver{cventry}{%
   \usebibmacro{begentry}%
   \usebibmacro{cvitem}%
-  {\usebibmacro{range-date}}%
+  {% print the date or the list-of-dates
+    \iffieldundef{year}{%
+      \printlist{dates}%
+    }{%
+      \usebibmacro{range-date}%
+    }%
+  }
   {%
     \ifnameundef{author}{}{\usebibmacro{author}\newunit}%
     \printmlfield{title}%
 \DeclareFieldFormat{note}{\mkbibparens{#1\adddot}}
 \DeclareFieldFormat{details}{\ifdetails\small#1\fi}
 
+\DeclareListFormat{dates}{%
+  \usebibmacro{string-to-date}{#1}%
+  \ifthenelse{\value{listcount}<\value{liststop}}
+    {\addcomma\space}
+    {}
+}
+
 % Specific
 \DeclareFieldFormat[study]{title}{\mkbibbold{#1}}
 
 \newbibmacro*{cvfinentry}{}
 
 % Common formats
+% Does the same thing as range-date but with a string instead
+\newbibmacro*{string-to-date}[1]{%
+  % localize the year macrso to avoid problems
+  \begingroup%
+  % Do we have a range?
+  \IfSubStr{#1}{/}%
+  {% Is range
+    \StrCut{#1}{/}\first\second%
+    \usebibmacro{string-to-single-date}{\first}%
+    \ifdefempty{\second}{%
+      \edef\abx@field@endyear{}
+    }{%
+     \usebibmacro{string-to-single-date}[end]{\second}%
+    }% 
+  }%
+  {% Is single date
+    \usebibmacro{string-to-single-date}{#1}%
+  }%
+  \usebibmacro{range-date}%
+  \endgroup%
+}
+
+\newbibmacro*{string-to-single-date}[2][]{%
+  % if string (#2) is emtpy do nothing
+  \ifdefempty{#2}{}{%
+    % else
+    \IfSubStr{#2}{-}%
+    {%
+      \StrCut{#2}{-}\year\rest%
+      \StrCut{\rest}{-}\month\day%
+      \csedef{abx@field@#1year}{\year}%
+      \csedef{abx@field@#1month}{\month}%
+      \csedef{abx@field@#1day}{\day}%
+    }%
+    {% Just a year in the date
+      \csedef{abx@field@#1year}{#2}%
+    }%
+  }%
+}
+
 \newbibmacro*{range-date}{%
   \iffieldundef{year}%
   {}%
diff --git a/cv.dbx b/cv.dbx
index f8b28a9b459b39be4fc1a1be649cf63a50d22679..e1f793e5e507a07acaf47df4e79f647eeae4e0e7 100644 (file)
--- a/cv.dbx
+++ b/cv.dbx
   date%
 }
 
+\DeclareDatamodelFields[type=list, datatype=literal]{dates}
+
 % Entries
 \DeclareDatamodelEntrytypes{course, cvmisc, position, project, study, thesis}
 
 % Data models
 \DeclareLocalizedDatamodelEntryfields[course]{%
+  dates,%
   date,%
   organization,%
   title,%
@@ -29,6 +32,7 @@
 }
 
 \DeclareLocalizedDatamodelEntryfields[cvmisc]{%
+  dates,%
   date,%
   title,%
   description%
 }
 
 \DeclareLocalizedDatamodelEntryfields[project]{
-  number,
-  title,
-  funding,
+  number,%
+  title,%
+  funding,%
   role,%
-  number,
-  period,
-  month,
+  number,%
+  period,%
+  month,%
   year%
 }