A consultation gets under way next week on plans for a second Scottish independence referendum, the SNP's Nicola Sturgeon has confirmed.
She told the party's Glasgow conference that an Independence Referendum Bill would be published next week.
It marks the first step to holding a second vote.
Ms Sturgeon said Scotland had the right to choose a different path if it was not allowed to protect its interests "within the UK".
The first Scottish independence referendum, which took place on 18 September, 2014, resulted in 55% of voters saying "no".
Ms Sturgeon told delegates that Scotland had the right to seek something better if there were prospects of an unstable future as part of the UK.
She said: "I am determined that Scotland will have the ability to reconsider the question of independence and to do so before the UK leaves the EU - if that is necessary to protect our country's interests.
"So, I can confirm today that the Independence Referendum Bill will be published for consultation next week."
On 24 June, the day after the UK voted to leave the EU, Ms Sturgeon said a second independence referendum was "highly likely".
Those who voted in Scotland backed remaining in Europe by 62% to 38% while the UK as a whole backed leave, by a margin of 52% to 48%.
However, Scottish Secretary David Mundell called on Ms Sturgeon to "commit her government to working constructively with the UK government to seize the opportunities that will bring, not taking Scotland back to the divisive constitutional debates of the past".
He said: "Constant talk of another independence referendum is creating uncertainty and damaging the Scottish economy at a time when our growth is lagging behind the UK as a whole."
Will a second independence referendum happen?
By BBC Scotland political editor Brian Taylor
Consultation does not mean decision. It does not mean a date for the ballot. It does not mean action. It does not mean a referendum will definitely happen. It means next to nothing.
However, there was in the speech a far more significant announcement which, shorn of rhetoric, drew relatively little applause.
That was when the FM said her government would put forward proposals - which they are already crafting - to maintain as much of Scotland's links with the EU as may be thought feasible, post Brexit.
Crucially, this would be within the UK. It would not require indyref2. It would not require independence. It would, however, require new powers for the Scottish Parliament - including the power to reach transnational agreements.
It would require, therefore, a flexible UK: perhaps on the lines of the relationship between Flanders and Belgium as a whole. Perhaps maintaining connections to the single market, Norway style. Perhaps also driven by the need to accord special status to Northern Ireland.
In essence, Ms Sturgeon is making that the core of her pitch. She is challenging Theresa May to smile upon this prospect, to take it seriously and, ultimately, to advance it as part of the UK Brexit pitch if it is judged worthwhile.
Ms Sturgeon's opening address also saw her issue a warning that the right wing of the Tory party was seeking to "hijack" the EU referendum result.
She told the 3,000 delegates gathered that the Tories were using the result as a "licence for xenophobia".
Ms Sturgeon insisted that the Prime Minister Theresa May needed to respect the 62% who voted to remain in the EU.
She also confirmed that SNP MPs would oppose Brexit legislation when it comes before the House of Commons in 2017.
The MSP said: "I can confirm today that SNP MPs will vote against the Brexit Bill when it comes before the House of Commons next year.
"That bill will repeal the legislation that enacted our EU membership. Scotland didn't vote for that and so neither will our MPs.
"But we will also work to persuade others - Labour, Liberals and moderate Tories - to join us in a coalition against a hard Brexit: not just for Scotland, but for the whole UK.
"The Conservative Party manifesto, on which Theresa May and all other Tory MPs were elected said this: 'We are clear about what we want from Europe. We say: yes to the Single Market'.
"The prime minister may have a mandate to take England and Wales out of the EU but she has no mandate whatsoever to remove any part of the UK from the single market."
Responding to Ms Sturgeon's address, the prime minister's spokeswoman said she was "absolutely committed to engaging with the people of Scotland, with understanding their interests and making sure that as we go through the process of negotiating the UK's exit, we do what's in the interest of the UK".
What message is Nicola Sturgeon sending to Theresa May?
By BBC Scotland editor Sarah Smith
Nicola Sturgeon told the SNP conference that not a day passes without someone telling her to "hurry up" with a second referendum on Scottish independence.
And every day someone tells her to "slow down".
It is certainly true that every day since the EU referendum the question is asked when, or if, the SNP's call for Indyref2 - as it's known - might happen.
With many commentators (myself included) concluding that the cautious, canny Sturgeon will not rush into a vote she knows she might lose.
Today Ms Sturgeon made very clear that she is prepared to trigger a second referendum if she feels that is the only way to protect Scotland from what she calls a "hard Brexit imposed by the hard right of the Tory party".
She was angered by what she heard from the prime minister at the Tory conference last week.
At the beginning of the three-day conference, if was announced that SNP MP Angus Robertson had been voted the new deputy of the party.
Mr Robertson defeated Edinburgh East MP Tommy Sheppard, Alyn Smith MEP and Inverclyde councillor Chris McEleny to take 52.5% of the votes cast.
About 120,000 SNP members were entitled to vote in the contest.