cgnieder / acro

acronyms for LaTeX
LaTeX Project Public License v1.3c
42 stars 9 forks source link

acro package across two types of languages #153

Closed DaftDogeee closed 4 years ago

DaftDogeee commented 4 years ago

I just use the acro package to typeset my thesis in Chinese, with the following example:

\documentclass[UTF8,a4paper,zihao=-4,fontset=fandol]{ctexart}

\usepackage{acro}

\DeclareAcronym{hi}{
    short = Hi,
    long = 你好,
    foreign = Hello}

\begin{document}

\ac{hi} % will generate 你好 (Hello, Hi)

\end{document}

This example meets the requirements in various Chinese environments. However, when I transfer to pure English environments, I want to locally let long be equal to foreign, and ignore foreign. The thing that I want to do, is

\documentclass[UTF8,a4paper,zihao=-4,fontset=fandol]{ctexart}

\usepackage{acro}

\DeclareAcronym{hi}{
    short = Hi,
    long = 你好,
    foreign = Hello}

\begin{document}

% Chinese

\ac{hi} % will generate 你好 (Hello, Hi)

\begingroup % pure English

\ac{hi} % expect to generate Hello (Hi)

\endgroup

\end{document}

In addition, are there some ways to use \MakeTextLowercase for the foreign in Chinese or for the long in English?

Thanks for your help, cgnieder!

DaftDogeee commented 4 years ago

By the way, the example should be compiled with xelatex.

cgnieder commented 4 years ago

Crosspost: https://tex.stackexchange.com/q/533809/

cgnieder commented 4 years ago

Here is a suggestion (which is not completely automatic):

% arara: xelatex: { interaction: nonstopmode }
\documentclass[UTF8,a4paper,zihao=-4,fontset=fandol]{ctexart}
\usepackage[english]{babel}
\babelprovide[import,main]{chinese}
\usepackage{acro}

\DeclareAcronym{hi}{
  short = Hi,
  long = \ifcurrentlanguage{english}{Hello}{你好},
  foreign = Hello
}

\newenvironment{english}
  {%
    \begin{otherlanguage}{english}%
    \acresetall\acsetup{display-foreign=false}%
  }
  {\end{otherlanguage}}

\begin{document}

Main: \ac{hi}

\begin{english}
  English: \ac{hi}
\end{english}

\end{document}

image

\ifcurrentlanguage is provided by the translations package which is loaded ba acro. If this is a viable way for you I'll also answer on TeX.sx.

DaftDogeee commented 4 years ago

Thanks for your reply, cgnieder!

The ctex document class offers the powerful support for Chinese, and thus the babel package is rarely used for Chinese. But your example also gives me some ideas to meet the requirements. The new example is

\documentclass[UTF8,a4paper,zihao=-4,fontset=fandol]{ctexart}

\usepackage{acro}
\usepackage{mfirstuc}

\newif\iftest   \testtrue
\newcommand{\testcmd}[2]{\iftest#1\else#2\fi}

\DeclareAcronym{hi}{
    short = Hi,
    long = \testcmd{你好}{hello hello},
    foreign = hello hello
}

\begin{document}
%\acsetup{foreign-format=\capitalisewords} % cannot be compiled
\ac{hi}

\begingroup
\testfalse
\acsetup{display-foreign=false}
\acsetup{long-format=\capitalisewords}

\acresetall
\ac{hi}

%\Ac{hi} % cannot be compiled
%\Acl{hi} % cannot be compiled
\endgroup

\acresetall
\ac{hi}

\end{document}

There are some new issues: 1) \Ac and \Acl cannot be compiled;

2) Even for your example, \Acl also cannot be compiled, it seems that the document cannot finish compiling;

3) Are there some ways to use \capitalisewords for foreign-format ?

By the way, my local version of acro is v2.9.

Many thanks~~

cgnieder commented 4 years ago

This compiles for me:

% arara: xelatex: { interaction: nonstopmode }
\documentclass[UTF8,a4paper,zihao=-4,fontset=fandol]{ctexart}

\usepackage{acro}
\usepackage{mfirstuc}

\newif\iftest   \testtrue
\newcommand{\testcmd}[2]{\iftest#1\else#2\fi}

\DeclareAcronym{hi}{
    short = Hi,
    long = \testcmd{你好}{hello hello},
    foreign = hello hello
}

\begin{document}

1: \ac{hi}

\begingroup
\testfalse
\acsetup{display-foreign=false}

\acresetall
2: \ac{hi}

3: \Ac{hi}
4: \Acl{hi}
\endgroup

\acresetall
5: \ac{hi}

\end{document}

image

´I need to take a deeper look why mfirstuc is not working.

DaftDogeee commented 4 years ago

Thanks again! It is very strange, and I cannot compile your latest example with v2.11d. I am not good at the LaTeX3 coding, here is the error from my log file. Could you please help me solve this problem again?

! Undefined control sequence.
\__acro_first_upper_case:n ...t_titlecase_first:n 
                                                  {#1}
cgnieder commented 4 years ago

It is dangerous to update single packages. My recommendation is to always update the TeX distribution. \text_titlecase_first:n was introduced not to long ago (January 2020 I think) into the l3kernel.

DaftDogeee commented 4 years ago

Thanks for your patience! \Ac also cannot be used with v2.9. I always use \ac for the Chinese environments, so I don't find this issue until today. I have read the log file, it seems that \testcmd cannot work well.

\documentclass[UTF8,a4paper,zihao=-4,fontset=fandol]{ctexart}

\usepackage{acro}

\newif\iftest   \testtrue
\newcommand{\testcmd}[2]{\iftest#1\else#2\fi}

\DeclareAcronym{hi}{
    short = Hi,
    long = \testcmd{你好}{hello hello},
    foreign = hello hello
}

\begin{document}

\Ac{hi}

\end{document}
! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.16 \Ac{hi}

The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

! Missing number, treated as zero.
<to be read again> 
                   _
l.16 \Ac{hi}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Extra \endcsname.
<recently read> \cs_end: 

l.16 \Ac{hi}

I'm ignoring this, since I wasn't doing a \csname.

! Extra \else.
<inserted text> ...\exp_after:wN \use_i:nn \else: 
                                                  \exp_after:wN \use_ii:nn \...
l.16 \Ac{hi}

I'm ignoring this; it doesn't match any \if.

! Extra \fi.
<recently read> \fi: 

l.16 \Ac{hi}

I'm ignoring this; it doesn't match any \if.

! Extra \fi.
<inserted text> ...:w \cs:w c__tl_change_case_\fi 
                                                  _\token_to_str:N \iftest _...
l.16 \Ac{hi}

I'm ignoring this; it doesn't match any \if.

! Missing number, treated as zero.
<to be read again> 
                   }
l.16 \Ac{hi}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Argument of \use_ii:nn has an extra }.
<inserted text> 
                \par 
l.16 \Ac{hi}

I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.

Runaway argument?
! Paragraph ended before \use_ii:nn was complete.
<to be read again> 
                   \par 
l.16 \Ac{hi}

I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
cgnieder commented 4 years ago

runs without error on my system (I have the frozen texlive 2019)

DaftDogeee commented 4 years ago

I also use the original texlive 2019 without updating anything...I will test with another PC.

DaftDogeee commented 4 years ago

I think the error is caused by my PC. But I still don't know how to solve this problem. Is it possible caused by two texlive in my PC? I am sure that I use texlive 2019 now.

DaftDogeee commented 4 years ago

Without \testcmd, it can be compiled normally.

cgnieder commented 4 years ago

You can add \listfiles to your preamble. Then you get a file list written in your log and you can check which versions are actually used:

 *File List*
 ctexart.cls    2019/05/29 v2.4.16 Chinese adapter for class article (CTEX)
   expl3.sty    2020-02-25 L3 programming layer (loader) 
l3backend-xdvipdfmx.def    2020-02-23 L3 backend support: xdvipdfmx
  xparse.sty    2020-02-25 L3 Experimental document command parser
l3keys2e.sty    2020-02-25 LaTeX2e option processing using LaTeX3 keys
ctexhook.sty    2019/05/29 v2.4.16 Document and package hooks (CTEX)
ctexpatch.sty    2019/05/29 v2.4.16 Patching commands (CTEX)
  fix-cm.sty    2015/01/14 v1.1t fixes to LaTeX
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
everysel.sty    2011/10/28 v1.2 EverySelectfont Package (MS)
ctexopts.cfg    2019/05/29 v2.4.16 Option configuration file (CTEX)
 article.cls    2019/12/20 v1.4l Standard LaTeX document class
  size12.clo    2019/12/20 v1.4l Standard LaTeX file (size option)
ctex-engine-xetex.def    2019/05/29 v2.4.16 XeLaTeX adapter (CTEX)
   xeCJK.sty    2020/02/18 v3.8.2 Typesetting CJK scripts with XeLaTeX
xtemplate.sty    2020-02-25 L3 Experimental prototype document functions
fontspec.sty    2020/02/21 v2.7i Font selection for XeLaTeX and LuaLaTeX
fontspec-xetex.sty    2020/02/21 v2.7i Font selection for XeLaTeX and LuaLaTeX
 fontenc.sty
fontspec.cfg
   xeCJK.cfg    2020/02/18 v3.8.2 Configuration file for xeCJK package
xeCJKfntef.sty    2020/02/18 v3.8.2 xeCJK font effect
    ulem.sty    2019/11/18
zhnumber.sty    2019/04/07 v2.7 Typesetting numbers with Chinese glyphs
zhnumber-utf8.cfg    2019/04/07 v2.7 Chinese numerals with UTF8 encoding
ctex-scheme-chinese-article.def    2019/05/29 v2.4.16 Chinese scheme for articl
e (CTEX)
ctex-name-utf8.cfg    2019/05/29 v2.4.16 Caption with encoding UTF8 (CTEX)
ctex-cs4size.clo    2019/05/29 v2.4.16 cs4size option (CTEX)
ctex-fontset-fandol.def    2019/05/29 v2.4.16 Fandol fonts definition (CTEX)
    ctex.cfg    2019/05/29 v2.4.16 Configuration file (CTEX)
    acro.sty    2020/02/03 v2.11c Typeset Acronyms
etoolbox.sty    2019/09/21 v2.5h e-TeX tools for LaTeX (JAW)
zref-abspage.sty    2019/11/29 v2.28 Module abspage for zref (HO)
zref-base.sty    2019/11/29 v2.28 Module base for zref (HO)
 ltxcmds.sty    2019/12/15 v1.24 LaTeX kernel commands for general use (HO)
infwarerr.sty    2019/12/03 v1.5 Providing info/warning/error messages (HO)
kvsetkeys.sty    2019/12/15 v1.18 Key value parser (HO)
kvdefinekeys.sty    2019-12-19 v1.6 Define keys (HO)
pdftexcmds.sty    2019/11/24 v0.31 Utility functions of pdfTeX for LuaTeX (HO)
   iftex.sty    2019/11/07 v1.0c TeX engine tests
etexcmds.sty    2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO)
 auxhook.sty    2019-12-17 v1.6 Hooks for auxiliary files (HO)
atbegshi.sty    2019/12/05 v1.19 At begin shipout hook (HO)
translations.sty    2018/02/28 v1.8 internationalization of LaTeX2e packages (C
N)
scrlfile.sty    2020/01/24 v3.29 KOMA-Script package (loading files)
acro.definitions.tex    
translations-basic-dictionary-english.trsl    (english translation file `transl
ations-basic-dictionary')
 ***********

Also, each time a package or other file is opened the log contains a line with the absolute path

(/usr/local/texlive/2019/texmf-dist/tex/latex/acro/acro.sty

where you can check where exactly TeX finds the file.

DaftDogeee commented 4 years ago

Thanks for your help, cgnieder~ I will debug it when I get rid of my thesis~

DaftDogeee commented 3 years ago

Hi, cgnieder, long time no see. @cgnieder

Recently, I notice that the acro package has a big update. Hence, based on the new features in v3.x, could you please give a "completely automatic" solution to this issue?

Furthermore, I think this issue may be combined with the Example 9 (acro.example.texsx-507726.tex) to show a comprehensive example. Two problems are solved, i.e., 1) How to use the foreign form in the non-english environment. 2) How to switch the foreign form in the pure english environment.