Hello all,

For the past day I've been struggling with an issue regarding the `siunitx`
package. I've tried using the `\unit` command to format some units, but I
kept getting an error message saying it can't operate while the `units`
package is loaded. I did some digging (read the "LaTeX Configuration" file
and compiled my file to TeX and read it), and figured out that the problem
was that Lyx was automatically inserting a `\usepackage{units}` command
when I used the `\unit` command in math mode (when using it in ERT it does
not \usepackage{units}` does not get inserted). I've somewhat gotten around
the problem by creating an empty `units.sty` file in my `texmf` directory,
which allows the file to compile correctly, but I still get the error from
`siunitx`.
I request a toggleable option for the `units` package, or to just stop
using it, as it has been superseded by `siunitx`. I attach below a minimal
LyX example and its compilation to LaTeX, in plain text (as I don't know if
this email can receive files). I've only kept the line
`\sisetup{inter-unit-product=\ensuremath{{\cdot}}}` in the preamble to show
the package `siunitx` does work with my hack but doesn't without it.
System information: Windows 11 Version 24H2, AMD64, LyX 2.4.3 (2025-01-09), Qt
Version (run&compile-time): 6.8.1
Humble regards,
Ethan

LyX:
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 620
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
\usepackage{siunitx}
\sisetup{inter-unit-product=\ensuremath{{\cdot}}}
\end_preamble
\use_default_options true
\maintain_unincluded_children no
\language american
\language_package default
\inputencoding auto-legacy
\fontencoding auto
\font_roman "default" "Times New Roman"
\font_sans "default" "Times New Roman"
\font_typewriter "default" "Times New Roman"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\spacing onehalf
\use_hyperref false
\pdf_bookmarks false
\pdf_bookmarksnumbered true
\pdf_bookmarksopen true
\pdf_bookmarksopenlevel 2
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize a4
\use_geometry true
\use_package amsmath 0
\use_package amssymb 0
\use_package cancel 0
\use_package esint 0
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_formatted_ref 0
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 1cm
\topmargin 2cm
\rightmargin 1cm
\bottommargin 3cm
\headheight 0cm
\headsep 0cm
\footskip 2cm
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip fullline
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 1
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\bullet 0 0 0 -1
\bullet 2 0 0 -1
\bullet 3 0 0 -1
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\docbook_mathml_prefix 1
\end_header

\begin_body

\begin_layout Standard
\begin_inset Formula
\[
1\unit{kg.m^{-1}}
\]

\end_inset


\end_layout

\begin_layout Standard
1
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
unit{
\backslash
kilo
\backslash
gram
\backslash
per
\backslash
meter}
\end_layout

\end_inset


\end_layout

\end_body
\end_document

LaTeX:
%% LyX 2.4.3 created this file.  For more info, see https://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[american]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[skip=\baselineskip]{parskip}
\usepackage{units}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=3cm,lmargin=1cm,rmargin=1cm,headheight=0cm,headsep=0cm,footskip=2cm}
\usepackage{setspace}
\onehalfspacing

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{siunitx}
\sisetup{inter-unit-product=\ensuremath{{\cdot}}}

\AtBeginDocument{
  \def\labelitemi{\normalfont\bfseries{--}}
  \def\labelitemiii{\normalfont\bfseries{--}}
  \def\labelitemiv{\normalfont\bfseries{--}}
}

\makeatother

\usepackage{babel}
\begin{document}
\[
1\unit{kg.m^{-1}}
\]

1 \unit{\kilo\gram\per\meter}
\end{document}
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to