Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 119039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:35:23+00:00 2026-05-11T03:35:23+00:00

I edited the question after David Hanak’s answer (thanks btw!). He helped with the

  • 0

I edited the question after David Hanak’s answer (thanks btw!). He helped with the syntax, but it appears that I wasn’t using the right function to begin with.

Basically what I want is to let the compiler ignore multiple definitions of a certain label and just use the first. In order to do that, I thought I’d just do something like this:

     \makeatletter     \newcommand{\mylabel}[1]{         \@ifundefined{#1}{\label{#1}}{X}     }     \makeatother 

This does not work though, because the first option is always chosen (it doesn’t matter if the label is defined or not). I think the \@ifundefined (and the suggested \ifundefined) only work for commands and not for labels, but I don’t really know much about LaTeX. Any help with this would be great! Thanks!

Much later update: I marked David Hanak’s response as the correct answer to my question, but it isn’t a complete solution, although it really helped me. The problem is, I think but I’m no specialist, that even though David’s code checks to see if a label is defined, it only works when the label was defined in a previous run (i.e. is in the .aux file). If two \mylabels with the same name are defined in the same run, the second will still be defined. Also, even if you manage to work around this, it will make LaTeX use the first label that you defined chronologically, and not necessarily the first in the text. Anyway, below is my quick and dirty solution. It uses the fact that counters do seem to be defined right away.

 \newcommand{\mylabel}[1]{%     \@ifundefined{c@#1}{%         \newcounter{#1}%         \setcounter{#1}{0}%     }{}%     \ifthenelse{\value{#1} > 0}{}{%         \label{#1}%         \addtocounter{#1}{1}%     }% } 

I’m not sure if it is necessary to initialize the counter to 0, as it seems like a likely default, but I couldn’t find if that was the case, so I’m just being safe. Also, this uses the ‘ifthen’ package, which I’m not sure is necessary.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:35:24+00:00Added an answer on May 11, 2026 at 3:35 am

    @ is a special character in LaTeX. To make your declaration syntactically correct, you’ll have to add two more lines:

    \makeatletter \newcommand{\mylabel}[1]{     \@ifundefined{#1}{\label{#1}}{X} } \makeatother 

    The first line turns @ into a normal letter, the last line reverses its effect.

    Update: You might also want to take a look at the ‘plain’ \ifundefined LaTeX macro.

    Update 2

    Okay, I did some research to figure out the answer to the real problem. The thing is that defining a label does not create a macro by that name; it prepends a ‘r@’ to it. So try the following:

    \makeatletter \newcommand{\mylabel}[1]{     \@ifundefined{r@#1}{\label{#1}}{X} } \makeatother 

    For more technical details, refer to line 3863 of latex.ltx in your LaTeX distribution (where it says \def\newlabel{\@newl@bel r}).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDITED and refined my question after Johannes's valuable answer bool b = true; volatile
I edited this question after i found a solution... i need to understand why
EDITED SO THE CODE IS CORRECT (THANKS TO ta.speot.is) - NEW QUESTION AT BOTTOM
I have this test page [edited by poster after question was answered] and something
I've heavily edited this question because responses indicated I wasn't being clear problem: UI
I have read that after select we use column-names but I have found a
Edited: (after seeing Luke's answer) I'm looking to develop a website and all the
Edited the question due to progressive insights :-) I am creating an app that
N.B This question has been significantly edited before the first answer was given. Hi,
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.