# a new command of the form ----------{TEX}----------

Is it possible to create a new command of the form ----------{TEX}----------?

For instance, I would like to have something like \nc{TEX} which produces "TEX" in the middle of the line and the rest of it should be filled with '-'.

\nc{TEX} -> ----TEX----

-
The rules at the side are solid or dashed? –  Gonzalo Medina May 20 at 23:17
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Heiko Oberdiek May 20 at 23:38

If you want more flexibility you can use tikz:

## Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\nc}[2][]{%
\tikz \draw [draw=black, ultra thick, #1]
($(current page.center)-(0.5\linewidth,0)$) --
($(current page.center)+(0.5\linewidth,0)$)
node [midway, fill=white] {#2};
}

\begin{document}

\nc{\TeX}

\nc[dashed]{\TeX}

\bigskip

\nc[draw=red]{$\displaystyle\sum_{i=0}^n i^2=\frac{1}{3}n\left(n+\frac{1}{2}\right)(n+1)$}

\nc[draw=blue, dotted]{$\displaystyle\sum_{i=0}^n i^2=\frac{1}{3}n\left(n+\frac{1}{2}\right)(n+1)$}

\end{document}

-

With this macro the rule is automatically vertically centered with respect to the size of the material. The optional argument is for the rule thickness (default 0.4pt, the standard size of rules).

\documentclass{article}

\newcommand{\nc}[2][0.4pt]{%
\sbox0{#1}%
\par\noindent
\makebox[\textwidth]{%
depth-\dimexpr(\ht0-\dp0)/2-(#1)/2\relax
\hfill
\ #2\ %
depth-\dimexpr(\ht0-\dp0)/2-(#1)/2\relax
\hfill
}%
\par
}

\begin{document}

\nc{\TeX}

\bigskip

\nc[1pt]{$\displaystyle\sum_{i=0}^n i^2=\frac{1}{3}n\left(n+\frac{1}{2}\right)(n+1)$}

\end{document}


-

The optional argument for \NC allows you to control the rule thickness:

\documentclass{article}%
\usepackage{xhfill}

\newcommand\NC[2][0.4pt]{%
\noindent\xrfill[0.65ex]{#1}~{#2}~\xrfill[0.65ex]{#1}}

\begin{document}

\NC{\TeX}

\NC[1pt]{\TeX}

\NC{Some other text}

\NC[1pt]{Some other text}

\end{document}


-

Here is a possible solution:

\documentclass{article}

\newcommand*\NiceLine{%
\par\noindent\raisebox{0.8ex}{\makebox[\linewidth]{\hrulefill\hspace{1ex}\raisebox{-0.8ex}{\TeX}\hspace{1ex}\hrulefill}}}

\begin{document}

\NiceLine

\end{document}


-

Lest you wanted dashes (or not):

\documentclass{article}

\usepackage{calc, dashrule}

\newcommand*{\nc}[1]{%
\par\noindent\hrulefill#1\hrulefill\par}
\newlength{\mcw}
\newlength{\mcwidth}
\newcommand*{\mc}[1]{%
\settowidth{\mcw}{#1}%
\setlength{\mcwidth}{.5\textwidth-.5\mcw}%
\par\noindent\rule[.5ex]{\mcwidth}{.4pt}#1\rule[.5ex]{\mcwidth}{.4pt}\par}
\newcommand*{\qc}[1]{%
\settowidth{\mcw}{#1}%
\setlength{\mcwidth}{.5\textwidth-.5\mcw}%
\par\noindent\hdashrule[.5ex][x]{\mcwidth}{.4pt}{2mm 1pt}#1\hdashrule[.5ex][x]{\mcwidth}{.4pt}{2mm 1pt}\par}

\begin{document}

\nc{TEX}
\mc{TEX}
\qc{TEX}

\end{document}


for baseline, mid and dashed rules:

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8213100433349609, "perplexity": 4761.543777393926}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-52/segments/1418802770557.39/warc/CC-MAIN-20141217075250-00053-ip-10-231-17-201.ec2.internal.warc.gz"}